[R] replacing NA for zero
arun
smartpink111 at yahoo.com
Wed Jun 13 00:25:12 CEST 2012
Hi,
Try this:
dat1<-data.frame(x=1:8,y=c(NA,0.12,0.25,0.11,NA,0.16,0.20,NA))
dat1[is.na(dat1)]<-0
dat1
x y
1 1 0.00
2 2 0.12
3 3 0.25
4 4 0.11
5 5 0.00
6 6 0.16
7 7 0.20
8 8 0.00
A.K.
----- Original Message -----
From: Silvia Lucato <slucato at lycos.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, June 12, 2012 5:55 PM
Subject: [R] replacing NA for zero
Dear R users,
I have a very basic query, but was unable to find a proper anwser.
I have the following data.frame
x y
2 0.12
3 0.25
4 0.11
6 0.16
7 0.20
and, due to further calculations, I need the data to be stored as
x y
1 0
2 0.12
3 0.25
4 0.11
5 0
6 0.16
7 0.20
8 0
How do I do the transformation?
Many many thjanks in advance.
______________________________________________
R-help at r-project.org 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.
More information about the R-help
mailing list