Dplyr:重新编码数字和字符向量

Dplyr:重新编码数字和字符向量,r,dplyr,recode,R,Dplyr,Recode,我脑子里有一个死亡的屏幕。如何在dplyr中使用recode 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

我脑子里有一个死亡的屏幕。如何在
dplyr
中使用
recode

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)

这是因为
recode
将向量作为参数,而不是数据帧:

data%>%mutate(time2=recode(time,`1`=0L))
数据%>%变异(char2=重新编码(char,aaa=0))
数据%>%变异(字符2=重新编码(如字符,aaa=0))