dataframe - I want to calculate a moving difference for my dataset below. -


enter image description here

how add column moving difference of column2?

for example: want add column have following values: (0,-372706.6,-284087.1, -119883.7, etc.)

here's way go it.

## small dataset  x <- data.frame(matrix(nrow=7,ncol=2,c(0,12,1,10,2,9.5,3,8,4,7,5,5,6,2),byrow = t)) names(x) <- c("time","count")  x[1,"diff"] <- na x[2:nrow(x),"diff"] <- rev(diff(rev(x$count))) 

there way plyr package well.


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -