Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dataframe 我想为下面的数据集计算移动差异。_Dataframe_Difference_Moving Average_Delta - Fatal编程技术网

Dataframe 我想为下面的数据集计算移动差异。

Dataframe 我想为下面的数据集计算移动差异。,dataframe,difference,moving-average,delta,Dataframe,Difference,Moving Average,Delta,如何添加另一个移动差异为Column2的列 例如:我想添加一列,其中包含以下值:(0,-372706.6,-284087.1,-119883.7,等等)这里有一个方法 ## For a 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

如何添加另一个移动差异为Column2的列


例如:我想添加一列,其中包含以下值:(0,-372706.6,-284087.1,-119883.7,等等)

这里有一个方法

## For a 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)))
##用于小数据集

您应该在问题中插入实际代码,而不是插入屏幕截图。