【发布时间】:2020-11-10 03:35:36
【问题描述】:
I am dealing with a data frame as shown in this image, but with 380 rows in total
不确定这是否会有所帮助,但假设我正在处理数据框:
df <- data.frame(c(-10:-1),c(-5:4),c(1:10))
我想提取第一列或第二列中包含数字“-5”的任何行。
在共享图像中,我想在“HomeTeam”或“AwayTeam”列中提取包含“Arsenal”的行,但我不知道该怎么做。
This is my attempt using grep()
但它显示以下消息:
"Error: Can't subset columns that don't exist. x The locations 12, 39, 45, 78, 98, etc. don't exist. i There are only 7 columns."
提到的位置正是我需要的行...
我想尝试其他一些过滤功能,例如 dplyr(),但我不明白它是如何工作的......而且我什至不确定它是否适合我想做的事情。
【问题讨论】:
-
欢迎来到 Stack Overflow。请make this question reproducible 以纯文本格式包含代码和示例数据 - 例如来自
dput(yourdata)的输出。我们无法从图像中复制/粘贴数据。 -
试试 League1819[grepl('Arsenal', League1819$HomeTeam)|grepl('Arsenal', League1819$AwayTeam), ]