[R] How to get R to ignore certain values when analyzing a column in a data table ?
Petr Pikal
petr.pikal at precheza.cz
Thu Jul 13 08:00:28 CEST 2006
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.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list