[R] replacing NA for zero

Rolf Turner rolf.turner at xtra.co.nz
Wed Jun 13 01:32:28 CEST 2012


A simplistic approach which works for the given example is as
follows:  Let your data frame be "X".  Do:

x <- 1:8
y <- numeric(8)
y[X$x] <- X$y
Y <- data.frame(x=x,y=y)

Then "Y" is the desired result.

     cheers,

         Rolf Turner

On 13/06/12 09:55, Silvia Lucato wrote:
>     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