What is the R equivalent of pandas.resample ()?

This is the closest link I found: https://stats.stackexchange.com/questions/5305/how-to-re-sample-an-xts-time-series-in-r

But I don’t see anything about the different methods of data aggregation (such as average, counting, anonymous function) that you can do in pandas.

For my program, I try to resample a discrete file every 2 minutes and take an average of two values ​​for each interval. Thank!

+4
source share
4 answers

If you use data.tableand lubridate, it might look something like this.

library(data.table)
library(lubridate)
#sample data
dt<-data.table(ts=seq(from=ymd('2015-01-01'), to=ymd('2015-07-01'),by='mins'), datum=runif(260641,0,100))

if you want to get data from a minute to an hour, you can do

 dt[,mean(datum),by=floor_date(ts,"hour")]

, , ,

dt[,lapply(.SD,mean),by=floor_date(ts,"hour")]

mean . "" "", "", "", "", "", "", "". , , , .

- .. 5- , .

-Jeffrey Ryan xts.

xts, , xts, (, , )

+2

R pandas resample(), xts. , , ts xts:

period.apply(ts, endpoints(ts, k=5, "minutes"), mean)
+1

R. . psuedocode

original Yourdata = Y
while i < number of iterations{
resampled = resample Y
"Do whatever you want to do with resampled; summary stats or whatever"
Sys.sleep(120)
}

Python

from time import sleep
sleep(120)

, . , , ( , ) .

-1

Source: https://habr.com/ru/post/1599564/


All Articles