r - tidyverse 中是否有 R 函数可以使用代码选择列的元素?
问题描述
我有两个数据框如下:
数据框 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)
然后运行连接,你应该没问题。
推荐阅读
- flutter - 底页初始高度为屏幕的一半,如果滚动则高度增加到全屏
- elixir - Elixir 中的流量限制
- chatbot - 在 Rasa Actions 中调用自定义函数
- r - 如何在 R Studio 中将所有整数值标记为“-1”?
- dart - 颤振设置状态 onPressed on RaisedButton
- php - POST localhost/.. 405(不允许的方法)
- reactjs - 在反应中异步加载 iframe
- angular - 如何重构从端点获取数据并再次接收数据
- python - Python:随机 StaleElementReferenceException
- python - 为什么使用 Flask 的 app.test_client() 而不是 requests.Session() 进行测试