0
使用R,有沒有一種正則表達式的方式,當'Column1'中的'Column2'在同一行上的'Column2'在其內容中包含一個單詞時,會得到'單元'?使用R,當column2在同一行包含一個單詞時,如何獲得'column1'中的'單元'以更新?
例如#如果我想包含在其中的任何地方「時間」來,然後‘下面
Column1 Column2
10 that is the time
10 what time is the match
0 where is the car?
目前我能得到它的非正則表達式的內容更新矩陣」列1至’10個細胞(只有在準確的單元格內容是「時間」使用下面的;
ds1$test[ds1$Column2 %in% "time"] <- 10
在此先感謝
如果可以,快速跟進問題。假裝我想要定位多個關鍵字及其正則表達式版本,是否如下所示;
df1 $ Column1 [grep(「time」,「clocks」,df1 $ Column2)] < - 10 –
@IanMcTavish在這種情況下,它會是'v1 < - c(「time」,「clocks」); pat < - paste0(「\\ b(」,paste(v1,collapse =「|」),「)\\ b」); grep(pat,df1 $ Column2)' – akrun
謝謝!如果在聯合的Column2單元格中檢測到文本,該版本是否也將數值分配給Column1? –