簡體   English   中英

使用R,當同一行的Column2包含一個單詞時,如何獲取“ column1”中的“ cell”以進行更新?

[英]Using R, How can i get a 'cell' in 'column1' to update when Column2 on the same row contains a word?

使用R,當同一行的“ Column2”的內容中包含一個單詞時,是否有正則表達式可以讓“ Column1”中的“單元格”更新?

例如#如果我希望在其中任何位置包含“時間”的單元格將矩陣“ Column1”更新為“ 10”,如下所示

Column1        Column2 
 10            that is the time 
 10            what time is the match
 0                 where is the car?

目前,我可以使它適用於非正則表達式(僅當使用以下命令時,確切的單元格內容為“時間”時);

ds1$test[ds1$Column2 %in% "time"] <- 10

提前致謝。

我們可以使用grep

df1$Column1[grep("time", df1$Column2)] <- 10

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM