我想更新新列中的值。
这是我的数据:
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()
命令。