r - Why does as.numeric not work? -
i have data.frame senti as:
p p p p p p p p p p p p i alter column of senti(a col of "n"), , seek alter each p 1, write code as:
senti[,4] <- data$category senti[senti=="p"] <- 1 senti[senti=="n"] <- -1 then, not number 1, seek convert number:
> senti<-as.numeric(senti) error: (list) object cannot coerced type 'double' > senti[1,1]<-as.numeric(senti[1,1]) > senti[1,1]+senti[1,1] error in senti[1, 1] + senti[1, 1] : non-numeric argument binary operator but, not work, not understand why. suppose there maybe set of original matrix, code long paste of them here. can help?
you first have info frame, have matrix ... it? sec effort convert single cell numeric, can't have mixed column in data.frame. need convert whole column @ once
senti[,1:4] <- sapply(senti[,1:4], as.numeric) it may possible 1 of columns list, str(senti) give? may need unlist column first.
r
No comments:
Post a Comment