Reputation: 41
I'm a complete R beginner, and am trying to do something pretty basic - make histograms of two vectors I imported from Excel.
The vectors are xa and xb. I tried hist(xa), and get the following error:
Error in hist.default(xa) : 'x' must be numeric
So I did some searching, and tried to remedy this using as.numeric(xa), and got:
Error: (list) object cannot be coerced to type 'double'
So I tried the as.list function, but it turned my vector into a matrix. Not really sure what's going on. The numbers in the vectors are all 4 digits between about -2 and +10. Any help would be greatly appreciated!
Upvotes: 4
Views: 15717
Reputation: 263411
Here's something you can try... no guarantees, since you have not given a working example:
newXa <- sapply(xa, as.numeric)
hist(newXa)
What should be done is to look at the structure of 'x'
str(x)
Then if 'xa' is how you are referring to x[['a']] you would do this:
hist( x[['a']] )
And if str(x)
showed that the "a" column were a factor, one might have more success with this:
hist( as.numeric(as.character(x[['a']])) )
Upvotes: 6