【发布时间】:2020-06-09 19:52:46
【问题描述】:
我想更新新列中的值。
这是我的数据:
people<- c("father", "parents", "father", "children", "girl", "boy", "grand father", "grand mother", "grandparents" )
dataset0 <- data.frame(people)
dataset0
然后输出:
father
parents
father
children
girl
boy
grand father
grand mother
grandparents
预期输出:
people people_update
father parents
parents parents
father parents
children children
girl children
boy children
grand father grandparents
grand mother grandparents
grandparents grandparents
我尝试使用replace()
dataset <- dataset0 %>%
mutate(people_update = replace(people, people =="girl", "children")) %>%
mutate(people_update = replace(people, people =="boy", "children"))
dataset
但这不起作用。第二个mutate() 命令取消了第一个mutate() 命令。
【问题讨论】: