我刚开始使用R,这是一个问题:我想从数字变量中的一个项目(列(中重新编码文本变量。由于我缺少值,所以我尝试这样回顾:
install.packages("dplyr")
library("dplyr")
zdf_all <- read.csv("Daten_einlesen.csv")
zdf2 <- read.csv("Daten_einlesen.csv", header=T, na.strings=c("","NA"))
zdf <- filter(zdf2, Status == "Complete")
names(zdf) [295] <- "pbc"
pbc = recode(zdf$value, 'Definitely agree'=5, 'Somewhat agree'=4, 'Neither agree or disagree'=3,'Somewhat disagree'=2, 'Definitely disagree'=1, 'NA'=0, as.factor.result=FALSE)
运行命令时,我会收到此警告消息:
Error in UseMethod("recode") :
no applicable method for 'recode' applied to an object of class "NULL"
为什么它说我有" null"类的对象?如何成功地重新编码我的物品?
我还尝试了不起作用的IFELSE函数。
install.packages("car")
car::recode(zdf$pbc, "'Definitely agree'=5; 'Somewhat agree'=4; 'Neither agree nor disagree'=3; 'Somewhat disagree'=2; 'Definitely disagree'=1; 'NA'=0")