[R] Replacing values without looping

wuffmeister hvemhva at gmail.com
Thu Jun 16 14:13:32 CEST 2011


I got an array similar to the one below, and want to replace all NAs with the
previous value.
99 8.2 b
NA 8.3 x
NA 7.9 x
98 8.1 b
NA 7.7 x
99 9.3 b
...

i.e. the first two NAs should be replaced to 99, whereas the last one should
be 98.

I would like to apply a function to reach row, checking if the value in col
1 is NA, and if it is, set the value to the previous row's col 1 value.

Haven't been able to do this without looping, which gets very slow for large
datasets...

--
View this message in context: http://r.789695.n4.nabble.com/Replacing-values-without-looping-tp3602247p3602247.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list