我想在名称栏中查看昵称
我创建了向量(char),后者转换为data.frames。现在我想针对每个名称查看昵称 y = c("Varun","Rivan","Jyothi","others")
y = data.frame(y)
y$nicknames = ""
View(y)
y$nicknames = ifelse(y$y =="Varun","Vast",(ifelse(y$y =="Jyothi","jo",
(ifelse(y$y =="Rivan","Kidoo","others")))))
它为我工作,但是需要查看简单易行的执行方式
需要在其他列中查看昵称
答案 0 :(得分:0)
使用dplyr
库中的case_when
:
y$nicknames <- case_when(
y$y == "Varun" ~ "Vast",
y$y == "Jyothi" ~ "jo",
y$y == "Rivan" ~ "Kidoo",
TRUE ~ "others"
)