The hypothetical case is that there exist NA in a data.frame
data.frame
> a <- c(1:5, NA, 7:10) > b <- 1:10 > c <- 1:10 > > data <-
Given your desired result (where you don't mind NA becoming 0), I guess the easiest thing is to first remove the NA values using is.na and then carry on as before.
NA
0
is.na
data[ is.na(data) ] <- 0 data.frame(t(apply(data,1,cumsum)))