I just started working with R and this is one of problems: I want to recode text variables from one item (column) in numeric variables. Since I had missing values, I tried to recode like this:
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)
When I run the command I get this warning message:
Error in UseMethod("recode") :
no applicable method for 'recode' applied to an object of class "NULL"
Why does it say I have an object of class of "NULL"? How can I recode my items succesfully?
I also tried the ifelse function which didn't work as well.
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")