简体   繁体   English

R中的grepl函数

[英]grepl function in R

I have a data set and I want to find the rows which include a specific word "result". 我有一个数据集,我想找到包含特定单词“结果”的行。 I used the following function but it seems it doesn't work correctly. 我使用了以下功能,但似乎无法正常工作。 Any suggestion? 有什么建议吗?

data$new<-data.frame(grepl("result",col1)) 


data:
col1                            col2
ABC result VDCbvdc home          22
fgc school                       34
university result home exam      45
exam math stat                   65

try data$new <- grepl("result",data$col1) 尝试data$new <- grepl("result",data$col1)

data$new should be assigned to a vector, but you're trying to feed it a data frame. 应该将data$new分配给一个向量,但是您正在尝试向它提供一个数据帧。 also, col1 only exists inside data , so you'll need data$col1 . 同样, col1仅存在于data内部,因此您需要data$col1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM