as.numeric() change for some but not other

Hello,
Here is something I couldn't figure out - when using as.numeric() to change the type of variables, which all are character, only a few of them did change but not all of them. below were the codes and results
final1<- within(final1, Bother <- as.numeric(Bother),
concentration <- as.numeric(concentration),
Depressed <- as.numeric(Depressed),
Effort <- as.numeric(Effort),
Hopeful<- as.numeric(Hopeful),
Fearful<- as.numeric(Fearful),
Restless<-as.numeric(Restless),
Happy <- as.numeric(Happy),
Lonely <- as.numeric(Lonely),
Not_Get_Going<-as.numeric(Not_Get_Going)
)
only Bother, Effort, Fearful, and Happy did change, but the rest of them did not.
Thanks in advance for help!
Jason

Check whether the variables that don't change all have valid numbers.

thanks, it seems not related to that.

Can you provide a reproducible example of the dataset?

The problem has been fixed now with using the following function
data[,'variable'] <- as.numeric(data[,'variable'])
Thanks for everyone support!
Jason

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.