replacing zeros by NAs

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

replacing zeros by NAs

Robert Douglas Kinley
something like ...
 
> x<-c(1,2,3,0,5,6,0)
> is.na(x[x==0])<-T
> x
[1]  1  2  3 NA  5  6 NA

~~~~~~~~~~~~~~~~
Robert  Kinley

~~~~~~~~~~~~~~~~


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: replacing zeros by NAs

tommaso.letterio
Other method:

a<-matrix(seq(1,20,2), 4,5)
a[c(1:2),c(2:4)]<-0

a[a==0]<-NA

----- Original Message -----
From: "Robert Kinley" <[hidden email]>
To: <[hidden email]>
Sent: Friday, June 12, 2009 11:59 AM
Subject: [R] replacing zeros by NAs


> something like ...
>
>> x<-c(1,2,3,0,5,6,0)
>> is.na(x[x==0])<-T
>> x
> [1]  1  2  3 NA  5  6 NA
>
> ~~~~~~~~~~~~~~~~
> Robert  Kinley
>
> ~~~~~~~~~~~~~~~~
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


--------------------------------------------------------------------------------



No virus found in this incoming message.
Checked by AVG - www.avg.com

17:59:00

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: replacing zeros by NAs

Henrique Dallazuanna
In reply to this post by Robert Douglas Kinley
Try this also:

 is.na(x) <- x == 0

On Fri, Jun 12, 2009 at 6:59 AM, Robert Kinley <[hidden email]>wrote:

> something like ...
>
> > x<-c(1,2,3,0,5,6,0)
> > is.na(x[x==0])<-T
> > x
> [1]  1  2  3 NA  5  6 NA
>
> ~~~~~~~~~~~~~~~~
> Robert  Kinley
>
> ~~~~~~~~~~~~~~~~
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: replacing zeros by NAs

Mike Prager
Often, data are computed in real (not integer) numbers, and in
such cases, comparison to zero is not as good as using a
tolerance level. Modifying slightly the suggestions of others, I
would use something like this:

my.tol <- 1e-50
x <- c(1.4, 2.97, 1.0e-100, pi, 0.2, 5.1, 6.8, 0.0)
print(x)
is.na(x) <- abs(x) < my.tol
print(x)


--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.