Re: [R] How to get R to ignore certain values when analyzing a column in a data table ?

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Thu 13 Jul 2006 - 16:00:28 EST


Hi

On 9 Jul 2006 at 20:01, Daryl Manning wrote:

To:             	r-help@stat.math.ethz.ch
From:           	Daryl Manning <dwm@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@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@precheza.cz



R-help@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 Received on Thu Jul 13 16:07:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 13 Jul 2006 - 18:14:16 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.