Here is a slight simplification to the first line based on the fact
that na.locf works column by column:
mat <- t(na.locf(t(mydata), fromLast = TRUE, na.rm = FALSE))
On Mon, Apr 5, 2010 at 1:46 PM, Peter Ehlers wrote:
> If I understand correctly what you want (according to your loop),
> you cou
If I understand correctly what you want (according to your loop),
you could use the na.locf function in pkg:zoo.
library(zoo)
mat <- t(apply(mydata, 1, na.locf, fromLast=TRUE, na.rm=FALSE))
dat <- as.data.frame(mat) ## since apply returns a matrix
-Peter Ehlers
On 2010-04-05 10:52, Anna Ste
#I wish to find the "next non-NA" value within each row of a data-frame.
#e.g. I have a data frame mydata. Rows 1, 2 & 3 have soem NA values.
mydata <- data.frame(matrix(seq(20*6), 20, 6))
mydata[1,3:5] <- NA
mydata[2,2:3] <- NA
mydata[2,5] <- NA
mydata[3,6] <- NA
mydata[1:3,]
#this loop acco
3 matches
Mail list logo