zoo

Apply a rolling function by group in r (zoo, data.table)

∥☆過路亽.° 提交于 2021-02-05 11:09:59
问题 I am having trouble doing something fairly simple: apply a rolling function (standard deviation) by group in a data.table. My problem is that when I use a data.table with rollapply by some column, data.table recycles the observations as noted in the warning message below. I would like to get NAs for the observations that are outside of the window instead of recycling the standard deviations. This is my approach so far using iris, and a rolling window of size 2, aligned to the right: library

Apply a rolling function by group in r (zoo, data.table)

六月ゝ 毕业季﹏ 提交于 2021-02-05 11:07:19
问题 I am having trouble doing something fairly simple: apply a rolling function (standard deviation) by group in a data.table. My problem is that when I use a data.table with rollapply by some column, data.table recycles the observations as noted in the warning message below. I would like to get NAs for the observations that are outside of the window instead of recycling the standard deviations. This is my approach so far using iris, and a rolling window of size 2, aligned to the right: library

Faster alternative to function 'rollapply'

霸气de小男生 提交于 2021-02-05 04:50:18
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

Faster alternative to function 'rollapply'

房东的猫 提交于 2021-02-05 04:49:54
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

merge.zoo removes time zone

廉价感情. 提交于 2020-12-12 10:52:09
问题 The result of merge.zoo does not have the same time zone as its input. Consider the following example library(zoo) zoo_a=zoo(data.frame(a=1:5), seq(as.POSIXct("2014-01-01 00:00:01",tz="UTC"), as.POSIXct("2014-01-01 00:00:05",tz="UTC"), by=1) ) zoo_b=zoo(data.frame(a=1:4), seq(as.POSIXct("2014-01-01 00:00:01",tz="UTC"), as.POSIXct("2014-01-01 00:00:05",tz="UTC"), by=1) ) zoo_merged=merge(zoo_a,zoo_b) time(zoo_merged)[1] #2013-12-31 19:00:01 EST time(zoo_a)[1] #2014-01-01 00:00:01 UTC time(zoo