Reputation: 3
I have searched high and low for what should be a very simple answer. In brief, while attempting to generate a distribution plot in R I kept receiving an error 'x' must be numeric. I have attempted to isolate the issue and believe I have found it, but have no idea why it is appearing. I have even moved form my initial data set (relatively complex with 200,000 values all between 0 and 1) to a very simple generic data set that still returns the same problems. I'll walk you through what I'm doing and you den tell me why I'm a bit slow.
> test <- read.table("/Users/timjenkins/Desktop/Test5hmcR/test.txt", header = T)
> str(test)
'data.frame': 200 obs. of 4 variables:
$ AGE : int 20 53 44 37 26 41 39 28 33 39 ...
$ HEIGHT: int 176 167 170 173 170 165 174 171 180 166 ...
$ WEIGHT: int 77 56 80 89 71 62 75 68 100 74 ...
$ CHOL : int 195 250 304 178 206 284 232 152 209 150 ...
> head(test)
AGE HEIGHT WEIGHT CHOL
1 20 176 77 195
2 53 167 56 250
3 44 170 80 304
4 37 173 89 178
5 26 170 71 206
6 41 165 62 284
> weight <- test$weight
> hist(weight)
Error in hist.default(weight) : 'x' must be numeric
> density(weight)
Error in density.default(weight) : argument 'x' must be numeric
> head(weight)
NULL
> str(weight)
NULL
> w <- as.numeric(weight)
> str(w)
num(0)
> head(w)
numeric(0)
Any thoughts? I am likely missing something very basic, but I have made many histograms in R and have never run into this problem until today and now it appears regardless of what data set I am working with, which tells me I am doing something very wrong (but at least I'm being consistent). Thanks in advance.
Upvotes: 0
Views: 120