I would like to be able to sum the value in each row with the value below and assign the result to a new column in R.
The following code (nearly) achieves what I want using a for loop (except that I have to manually do the last row - which is not really a problem). I would like to do a similar thing but using an apply function since the for loop is very slow on my large dataset - however I can't figure out the apply syntax.
data<-data.frame(runif(10))
data$x<-
for (i in 1:nrow(data)) {
data[i,2 ] <- data[i,1]+data[i+1,1]
}