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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -