[英]Using R, How can i get a 'cell' in 'column1' to update when Column2 on the same row contains a word?
Using R, is there a regex way that I get a 'cell' in 'Column1' to update when 'Column2' on the same row contains a word within its contents? 使用R,当同一行的“ Column2”的内容中包含一个单词时,是否有正则表达式可以让“ Column1”中的“单元格”更新?
For example# If I wanted cells that contain 'time' anywhere in them to then update the matrix' Column1 to '10' as below 例如#如果我希望在其中任何位置包含“时间”的单元格将矩阵“ Column1”更新为“ 10”,如下所示
Column1 Column2
10 that is the time
10 what time is the match
0 where is the car?
Currently I can get it to work for non regex (only if the exact cell contents is 'time' using the below; 目前,我可以使它适用于非正则表达式(仅当使用以下命令时,确切的单元格内容为“时间”时);
ds1$test[ds1$Column2 %in% "time"] <- 10
Thanks in advance. 提前致谢。
我们可以使用grep
df1$Column1[grep("time", df1$Column2)] <- 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.