Daryl Manning
2006-Jul-10 03:01 UTC
[R] How to get R to ignore certain values when analyzing a column in a data table ?
Apologies if this is in (one of the many) manuals somewhere... Trying to switch to R from other stats programs. Basically, I have a large data table I've dumped from a DB, some of the values which are nulls '-' which I've converted to zeros. I've read it in using read.table fine. I want R to ignore the zero values when graphing or doing various other calculations. Is there a way to do this ? I did try to use NA but kept getting errors that x must be numeric. thanks in advance, Daryl.
Prof Brian Ripley
2006-Jul-10 06:35 UTC
[R] How to get R to ignore certain values when analyzing a column in a data table ?
On Sun, 9 Jul 2006, Daryl Manning wrote:> Apologies if this is in (one of the many) manuals somewhere... Trying > to switch to R from other stats programs. > > Basically, I have a large data table I've dumped from a DB, some of > the values which are nulls '-' which I've converted to zeros. I've > read it in using read.table fine. > > I want R to ignore the zero values when graphing or doing various > other calculations. > > Is there a way to do this ? > > I did try to use NA but kept getting errors that x must be numeric.Did you use numeric NA? That is the way to so this, so you will need to give a reproducible example (as the posting guide asks). -- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Petr Pikal
2006-Jul-13 06:00 UTC
[R] How to get R to ignore certain values when analyzing a column in a data table ?
Hi On 9 Jul 2006 at 20:01, Daryl Manning wrote: To: r-help at stat.math.ethz.ch From: Daryl Manning <dwm at wakatara.com> Date sent: Sun, 9 Jul 2006 20:01:10 -0700 Subject: [R] How to get R to ignore certain values when analyzing a column in a data table ?> Apologies if this is in (one of the many) manuals somewhere... Trying > to switch to R from other stats programs. > > Basically, I have a large data table I've dumped from a DB, some of > the values which are nulls '-' which I've converted to zeros. I've > read it in using read.table fine. > > I want R to ignore the zero values when graphing or doing various > other calculations. > > Is there a way to do this ? > > I did try to use NA but kept getting errors that x must be numeric.What does str(your.data) says about your data? I presume it is factor. datafr <- data.frame(a=rnorm(10), b=rnorm(10)) datafr[3,1]<-0> datafr$a[1] -0.1645236 -0.2533617 0.0000000 0.5566632 -0.6887557 - 0.7074952 0.3645820 0.7685329 -0.1123462 0.8811077> mean(datafr$a)[1] 0.06444035> datafr$a==0[1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE> datafr$a[datafr$a==0][1] 0> datafr$a[datafr$a==0]<-NA> mean(datafr$a)[1] NA> mean(datafr$a, na.rm=T)[1] 0.07160039>works OK. HTH Petr> > thanks in advance, > Daryl. > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz