本文介绍了根据grep替换数据值导致R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框。其中一列的值如下所示:

其他值。现在我想重命名每个有WIND变化的值,用WIND。我知道如何找到需要替换的值:

  grep(WIND,df $ col1)

但没有如何替换这些值。感谢。

解决方案

您可以使用grepl对这些值的原始列进行子集化,并替换

  df $ col1 [grepl(WIND,df $ col1)]<  - WIND
pre>

I have a data frame. One of the columns has values like:

among the other values. Now I want to rename every value that has some variation of "WIND" in it, with "WIND". I know how to find values that I need to replace:

grep("WIND", df$col1)

but not how to replace those values. Thanks.

解决方案

You can just subset the original column for these values by using grepl and replace

df$col1[grepl("WIND",df$col1)]<-"WIND"

这篇关于根据grep替换数据值导致R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 00:00