简体   繁体   中英

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?

For example# If I wanted cells that contain 'time' anywhere in them to then update the matrix' Column1 to '10' as below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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