【问题标题】:Replacing Column row values if it contains a string or character in R如果列包含 R 中的字符串或字符,则替换列行值
【发布时间】:2016-11-16 01:49:40
【问题描述】:

我目前正在尝试更改数据框列中的性别值以保持一致性。 我目前有以下代码,但它不会更改任何行值。它为每个值一致地打印“男性”,但它不会在数据框中更新。

count <- 0
for(i in mySubset$Gender){
  count = count + 1
  if('Male' %in% i){
    mySubset$Gender[count] <- 'male'
    print(mySubset$Gender[count])
  }
}

【问题讨论】:

  • 你能展示样本数据和想要的输出吗?

标签: r replace


【解决方案1】:

我不确定你在问什么,但听起来你想在任何时候用其他东西替换列中的“男性”?

如果是这样..你可以这样做:

 dataframe$gender[which(dataframe$gender=="Male")] <- "NewValue"

最好有一个例子。

【讨论】:

    猜你喜欢
    • 2020-07-26
    • 2022-08-08
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多