我有两个数据框如下:
数据框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
我已经搜索过,但没有找到解决方案。非常感谢您的帮助。
我认为发生错误是因为在 DF2 中你有两次列名(如 Artem Sokolov 所示),并且 R 正在读取代码作为因子而不是整数值。
df2 <- read.table(text = " Code Name
12 Hogo
14 Smith
17 Rose
16 John
19 Noor
24 Matt
", header = TRUE)
然后运行连接,你应该没问题。