我心中有一个死亡的画面。如何在recode
中使用dplyr
?
data = data.frame(id=rep(1:10, each=1), time=seq(1:5), char = strrep("a", 3))
library(dplyr) # everything throws an error
data %>% recode(time, `1` = 0)
data %>% recode(time, `1` = 0L)
data %>% recode(time, 1 = 0)
data %>% recode(time, 1 = 0L)
data %>% recode(char, aaa = 0)
data %>% recode(time, "aaa" = 0)
最诚挚的问候
答案 0 :(得分:2)
这是因为recode
将向量作为参数,而不是data.frame:
data %>% mutate(time2 = recode(time, `1` = 0L))
data %>% mutate(char2 = recode(char, aaa = 0))
data %>% mutate(char2 = recode(as.character(char), aaa = 0))