且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据条件更改列中所有字符串的值

更新时间:2023-01-20 11:16:36

欢迎使用***!我已经回答了您的问题,但是将来,请提供一小部分数据样本,以便我们更轻松地解决您的问题。值得深思:如何制作可重复的例子

Welcome to ***! I've answered your question, but in the future, please include a small sample of your data so it's easier for us to solve your problem. Food for thought: How to make a reproducible example

require(plyr)
require(dplyr)


# Since you haven't provided a data sample, I'm going to assume your dataframe is named "DF" and your column's name is "Drive"

# Set everything to lowercase to pare down uniqueness
DF <- mutate(DF, Drive = replace(Drive, Drive, tolower(Drive)))


# You'll need one line like this for each replacement.  Of the following form:
#     <column_name> = replace(<column_name>, <condition>, <new value>)
DF <- mutate(DF, Drive = replace(Drive, Drive == "4 wheel drive", "4WD"))