Mag. Ferri Leberl
2005-Apr-06 14:57 UTC
[R] Error in hist.default(A) : `x' must be numeric
Dear everybody! I have load a list A of numbers and want a histogram to be drawn. on hist(Y) the Machine returns: Error in hist.default(A) : `x' must be numeric I found out, that the list is of type data.frame. Y<-as.numeric(Y) returns Error in as.double.default(A) : (list) object cannot be coerced to double What schould I do? Than you in advance!
Mag. Ferri Leberl wrote:> Dear everybody! > I have load a list A of numbers and want a histogram to be drawn. > on > hist(Y) > the Machine returns: > Error in hist.default(A) : `x' must be numeric > I found out, that the list is of type data.frame. > Y<-as.numeric(Y) > returns > Error in as.double.default(A) : (list) object cannot be coerced to double > What schould I do? > Than you in advance!Extract the relevant vector from your data frame Y (this is a very prbably guess). Uwe Ligges> ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Mag. Ferri Leberl wrote on 4/6/2005 9:57 AM:> Dear everybody! > I have load a list A of numbers and want a histogram to be drawn. > on > hist(Y) > the Machine returns: > Error in hist.default(A) : `x' must be numeric > I found out, that the list is of type data.frame. > Y<-as.numeric(Y) > returns > Error in as.double.default(A) : (list) object cannot be coerced to double > What schould I do? > Than you in advance! >The error messages cannot be more explicit. Y is a list (or data.frame). If you're trying to plot a histogram of a component in Y, use the "[[" or "$" extractors. E.g. Y <- data.frame(x = rnorm(100)) hist(Y$x) I would suggest you learn to use ?str if you don't know what Y is. --sundar
> From: Uwe Ligges > > Mag. Ferri Leberl wrote: > > Dear everybody! > > I have load a list A of numbers and want a histogram to be drawn. > > on > > hist(Y) > > the Machine returns: > > Error in hist.default(A) : `x' must be numeric > > I found out, that the list is of type data.frame. > > Y<-as.numeric(Y) > > returns > > Error in as.double.default(A) : (list) object cannot be > coerced to double > > What schould I do? > > Than you in advance! > > Extract the relevant vector from your data frame Y (this is a very > prbably guess).I suspect Ferri might have the numbers in one line in a file, and read them into R with read.table(). That would put the numbers into a data frame with n variables and one observation. If that's the case, just replacing read.table() with scan() should do it. Andy> Uwe Ligges >