#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 accomplishes the task; I am tryign toi learn a "better" way

for(i in (ncol(mydata)-1):1 ){
mydata[,i] <- ifelse(is.na(mydata[,i])==TRUE,mydata[,i+1],mydata[,i])
}

mydata[1:3,]
#Thank you. I appreciate the help.



      
	[[alternative HTML version deleted]]

