hi! i'm quite new in R and i don't understand why this statement doesn't work:> mode(mensuel$VARIANCE.PRIX)[1] "numeric"> storage.mode(mensuel$VARIANCE.PRIX)[1] "integer"> mean(mensuel$VARIANCE.PRIX)[1] NA Warning message: argument is not numeric or logical: returning NA in: mean.default(mensuel$VARIANCE.PRIX) Thanks for help! ___________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 25 Jul 2002, [iso-8859-1] jimmy melinard wrote:> i'm quite new in R and i don't understand why this > statement doesn't work: > > > mode(mensuel$VARIANCE.PRIX) > [1] "numeric" > > storage.mode(mensuel$VARIANCE.PRIX) > [1] "integer" > > mean(mensuel$VARIANCE.PRIX) > [1] NA > Warning message: > argument is not numeric or logical: returning NA in: > mean.default(mensuel$VARIANCE.PRIX)A bit short on details here. mean.default starts if (!is.numeric(x) && !is.complex(x) && !is.logical(x)) { warning("argument is not numeric or logical: returning NA") return(as.numeric(NA)) } so your argument fails is.numeric(x). Here's such an example> mode(x)[1] "numeric"> storage.mode(x)[1] "integer"> is.numeric(x)[1] FALSE> class(x)[1] "factor" so I guess you are trying to take the mean of a factor. That makes no sense, and R rightly objects. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
jimmy melinard <jmelinard at yahoo.fr> writes:> hi! > i'm quite new in R and i don't understand why this > statement doesn't work: > > > mode(mensuel$VARIANCE.PRIX) > [1] "numeric" > > storage.mode(mensuel$VARIANCE.PRIX) > [1] "integer" > > mean(mensuel$VARIANCE.PRIX) > [1] NA > Warning message: > argument is not numeric or logical: returning NA in: > mean.default(mensuel$VARIANCE.PRIX)It certainly looks odd... I bet that the variable in question is a factor object, in which case we have the effect that> is.numeric(x)[1] FALSE> is.integer(x)[1] TRUE> mode(x)[1] "numeric" It's a complicated issue; I don't think it counts as a bug. Factors really should not be treated as numeric vectors even if they are internally stored as integers, so the point is rather that you shouldn't expect is.numeric(x) and mode(x)=="numeric" to be the same thing. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi, Without knowing what the object contains, it's hard to tell. Factor objects are numeric mode but generally screw up when treated as numbers. See what happens when you enter: class(mensuel$VARIANCE.PRIX) and you may be able to get away with: mean(unclass(mensuel$VARIANCE.PRIX)) Jim -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._