R 如何提取任何列中包含特定字符串的行

R 如何提取任何列中包含特定字符串的行,r,dplyr,R,Dplyr,不确定这是否有帮助,但假设我正在处理数据帧: df您可以使用grepl: sampleArsenal <- subset(league1819, grepl('Aresenal', HomeTeam) | grepl('Aresenal', AwayTeam)) 使用df欢迎使用堆栈溢出。请以纯文本格式包含代码和示例数据-例如,dput(yourdata)的输出。我们无法从图像中复制/粘贴数据。请尝试league1

不确定这是否有帮助,但假设我正在处理数据帧:


df您可以使用
grepl

sampleArsenal <- subset(league1819, grepl('Aresenal', HomeTeam) | 
                                    grepl('Aresenal', AwayTeam))

使用
df欢迎使用堆栈溢出。请以纯文本格式包含代码和示例数据-例如,
dput(yourdata)
的输出。我们无法从图像中复制/粘贴数据。请尝试league1819[grepl('Arsenal',league1819$HomeTeam)124pl('Arsenal',league1819$AwayTeam),]天哪,这非常有效。非常感谢你,先生!很抱歉以一种不可复制的方式提出这个问题,因为我对R非常陌生。。。不知道如何生成类似的案例。非常感谢!
library(dplyr)
library(stringr)

league1819 %>% 
   filter(str_detect(HomeTeam, 'Aresenal') | str_detect(AwayTeam, 'Aresenal'))
if(!require(tidyverse)) install.packages('tidyverse'); library(tidyverse) #to load the package, just in case you haven't already!
df <- data.frame(c(-10:-1),c(-5:4),c(1:10))
colnames(df) <- c("col1", "col2", "col3")
df %>% filter(col1 %in% "-5" | col2 %in% "-5")
df %>% filter(col1 %in% "-5" & col2 %in% "-5")
sample_Arsenal <- league1819 %>% filter(HomeTeam %in% "Arsenal" | AwayTeam %in% "Arsenal")