简体   繁体   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?

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.

相关问题 如何为遵循 R 中结构 column1*column2 的新列分配名称? - How to assign a name to a new column that follows the structure column1*column2 in R? 如何合并其中column1是column2的子字符串的数据框 - How to merge data frames where column1 is substring of column2 如果第一行的第一列包含“ Region”(区域)词,则将整行作为标题。如何在R中进行编码? - if first column of first row contains “Region” word then make that entire row as header.how can i code this in R? 根据两个R中的匹配列从column2(dataframe2)中减去column1(dataframe1) - subtract column1 (dataframe1) from column2 (dataframe2) based on matching column in both R R:来自 column1 的字符串匹配从 column2 的行中选择数据以创建 column3? - R: String match from column1 selects data from column2's rows to create column3? R:对于 dfs 列表,过滤 Column1 中的值,以提取另一个 Column2 的平均值和 SD(仅在 Column1 中具有过滤值的行) - R: For a list of dfs, filter for a value in Column1, to extract mean and SD of another Column2 (only of rows with the filtered value in Column1) 如果column2是NA,则在column1上联接,否则在column1和column2上联接 - If column2 is NA join on column1 else join on column1 and column2 读取以竖线和逗号分隔的文件:| column1 |,| column2 | - Read files that are pipe AND comma delimited: |column1|,|column2| 如何找到哪一列包含与 R 中另一指定列相同的值? - How can I find which column contains the same value as another specified column in R? 当我在R中输入列元素作为输入时,如何获得整行? - How can I get the whole row when I give a column's element as input in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM