【发布时间】:2019-11-22 17:58:18
【问题描述】:
我有两个数据框如下:
数据框 1
df1 <- read.table(text = " Place Code Name
A 12 Hogo
C 14 Smith
C 17 Rose
D 16 John
A 19 Noor
B 12 Hogo
C 16 John
D 19 Noor
A 24 Matt
D 23 Kim
", header = TRUE)
数据框 2
df2 <- read.table(text = " Code Name
Code Name
12 Hogo
14 Smith
17 Rose
16 John
19 Noor
24 Matt
", header = TRUE)
我想根据如下代码选择A和C
Place Code Name
A 12 Hogo
C 14 Smith
C 17 Rose
C 16 John
A 19 Noor
A 24 Matt
我已经搜索过,但没有找到解决方案。非常感谢您的帮助。
【问题讨论】:
-
您要加入吗?
-
试试
left_join(df2, df1) -
你不能只做 filter(df1, Place %in% c("A", "C")) 吗?
-
@User20100,即使您有两个数据框,在代码上加入 left_join() 将解决您的问题,如 akrun 上面所说的
-
@User20100:您收到此错误是因为您在
df2的定义中列出了两次列名Code和Name。修正定义,错误就会消失。