在频率表中延长日期

时间:2015-12-16 13:57:01

标签: r date dataframe

我有不同的数据集,如下所示:

structure(c(1414406460, 1414635660, 1414636260, 1414636920, 1414637040, 
1414639020, 1414711140, 1414714500, 1414718760, 1414718820, 1414727520, 
1414727640, 1414727760, 1414898220, 1414898880, 1414899000, 1414899120, 
1414899240, 1414899300, 1414899480, 1414899600, 1414900140, 1414900260, 
1414900560, 1414900620, 1414900860, 1414901040, 1414919940, 1414920420, 
1414951320, 1414971720, 1414977600, 1414977660, 1414978620, 1414984980, 
1414988100, 1414988160, 1414989000, 1414989240, 1414989900, 1414990020, 
1414990080, 1414990320, 1414990500, 1414990920, 1414991100, 1414991220, 
1414991340, 1414991940, 1414992240, 1414992780, 1414992900, 1414993020, 
1414993140, 1415001600, 1415001660, 1415001720, 1415001840, 1415001960, 
1415002140, 1415002260, 1415003280, 1415003340, 1415018040, 1415040780, 
1415040900, 1415040960, 1415041080, 1415041320, 1415041440, 1415041560, 
1415041980, 1415042220, 1415042280, 1415042400, 1415042820, 1415043240, 
1415043360, 1415043420, 1415043540, 1415043600, 1415043660, 1415043720, 
1415043840, 1415043900, 1415044020, 1415044260, 1415044320, 1415044440, 
1415044560, 1415044620, 1415044680, 1415044800, 1415044860, 1415044920, 
1415044980, 1415045100, 1415045160, 1415045280, 1415045340, 1415045400, 
1415045460, 1415045520, 1415045700, 1415045760, 1415045820, 1415045940, 
1415046000, 1415046120, 1415046240, 1415046360, 1415046420, 1415046540, 
1415046600, 1415046720, 1415046780, 1415046900, 1415047020, 1415047080, 
1415047140, 1415047260, 1415047320, 1415047380, 1415047440, 1415047560, 
1415047620, 1415047680, 1415047740, 1415047800, 1415047920, 1415048040, 
1415048160, 1415048280, 1415048340, 1415048460, 1415048520, 1415048580, 
1415048640, 1415048760, 1415048820, 1415048940, 1415049000, 1415049060, 
1415049120, 1415049180, 1415049420, 1415049600, 1415049720, 1415049780, 
1415049900, 1415049960, 1415050020, 1415050140, 1415050320, 1415050500, 
1415050620, 1415050860, 1415050980, 1415051220, 1415051520, 1415051580, 
1415051700, 1415051760, 1415051880, 1415051940, 1415052000, 1415052120, 
1415052180, 1415052240, 1415052360, 1415052540, 1415052660, 1415052720, 
1415052780, 1415052900, 1415053020, 1415053080, 1415053140, 1415053260, 
1415053380, 1415053440, 1415053500, 1415053560, 1415053620, 1415053680, 
1415053800, 1415053860, 1415053980, 1415054100, 1415054160, 1415054760, 
1415054820, 1415055120, 1415055180, 1415055480, 1415056920, 1415057160, 
1415057760, 1415057760, 1415058720, 1415067660, 1415067780, 1415067900, 
1415068020, 1415068080, 1415068140, 1415068980, 1415069100, 1415069400, 
1415069520, 1415069580, 1415070000, 1415070060, 1415075760, 1415076720, 
1415076840, 1415077200, 1415077500, 1415077620, 1415082600, 1415082660, 
1415083140, 1415083260, 1415083380, 1415083440, 1415083500, 1415083800, 
1415084100, 1415136600, 1415141340, 1415142780, 1415212920, 1415304360, 
1415319300, 1415319900, 1415320320, 1415329140, 1415337660, 1415338680, 
1415338980, 1415339040, 1415339160, 1415348640, 1415348820, 1415348940, 
1415349000, 1415349060, 1415349120, 1415349180, 1415371200, 1415371320, 
1415371500, 1415371800, 1415371920, 1415372040, 1415372100, 1415372160, 
1415372220, 1415372280, 1415372340, 1415384520, 1415384580, 1415384640, 
1415391720, 1415391840, 1415396160, 1415396580, 1415396760, 1415396940, 
1415397780, 1415398080, 1415398380, 1415398380, 1415413620, 1415413680, 
1415413740, 1415413800, 1415413860, 1415414040, 1415414400, 1415421900, 
1415461920, 1415472240, 1415479740, 1415482920, 1415483280, 1415508780, 
1415509020, 1415509140, 1415509620, 1415509800, 1415513760, 1415513880, 
1415513940, 1415521980, 1415522040, 1415522100, 1415542260, 1415546520, 
1415566740, 1415566800, 1415568300, 1415568360, 1415581380, 1415581560, 
1415581620, 1415595000, 1415595240, 1415595480, 1415595540, 1415595720, 
1415596560, 1415597100, 1415598360, 1415598540, 1415598960, 1415609160, 
1415639700, 1415639760, 1415639880, 1415656320, 1415664360, 1415664480, 
1415667960, 1415668500, 1415668740, 1415671620, 1415686740, 1415733660, 
1415744280, 1415753340, 1415833500, 1415833620, 1415863260, 1415920320, 
1415927760, 1415929020, 1415929260, 1415929320, 1415929500, 1415929920, 
1415938560, 1415938920, 1415939400, 1416018540, 1416018600, 1416090120, 
1416090300, 1416090360, 1416090480, 1416099900, 1416188640, 1416188700, 
1416189120, 1416189240, 1416635940, 1416636000, 1416638400, 1416638520, 
1416639180, 1416702720, 1416811860, 1416811980, 1416812040, 1416875940, 
1416876000, 1416876060, 1416977640, 1416978360, 1417047780, 1417047840, 
1417066620, 1417066680, 1417219320, 1417221240, 1417221300, 1417221540, 
1417221600, 1417222740, 1417226580, 1417226640, 1417226700, 1417240560, 
1417300800, 1417301400, 1417307280, 1417307400, 1417314780, 1417314900, 
1417484160, 1417489200, 1418166300, 1418166540, 1418280240, 1418342280, 
1418342340, 1418703240, 1418703240, 1420096320, 1420761360, 1420761720, 
1420761840, 1420762020, 1421724780, 1422230580, 1422238380, 1422238500, 
1422238560, 1422238620, 1422506820, 1423182120, 1423273080, 1423273200, 
1423273260, 1423355820, 1424655360, 1424657520, 1424661840, 1424661900, 
1424671260, 1424832840, 1424839980, 1424840340, 1424841900, 1424842020, 
1424842800, 1424843040, 1425436080, 1425436200, 1425436320, 1425438960, 
1425439020, 1425959880, 1426120200, 1426996140, 1426996380, 1427074800, 
1427078100, 1427334360, 1427334420, 1427334660, 1427587800, 1427676780, 
1427676900, 1427676960, 1429924860, 1429925220, 1429925520, 1442449440, 
1443917580, 1444026600, 1444026780, 1444085880, 1444091040, 1444113300, 
1444122900, 1444432680, 1444462920, 1444462980, 1444463040, 1445056380, 
1445057700, 1445142420, 1445219160, 1445224500), class = c("POSIXct", 
"POSIXt"), tzone = "America/Anguilla")

现在我想计算每个日期/时间频率与30分钟时间步长的频率。我使用以下代码执行此操作:

timestep = "30 min"
det_interval = data.frame(table(cut(dateseq, breaks = timestep)))

但是我的学习期间提前开始,正好是一年。那么如何扩展频率表,使其从" 2014-10-21 00:00:00"然后停在" 2015-10-21 23:59:59"?

我尝试制作一个单独的时间序列,但后来我必须将它与以下DF合并:

timestep = "30 min"
start = "2014-10-21 00:00"
end = "2015-10-21 23:59"

timeseq = seq(from = as.POSIXct(start), to = as.POSIXct(end), by = timestep)

1 个答案:

答案 0 :(得分:1)

我认为应该这样做。您可以将一系列中断传递给cut(),而不是步骤(从数据的最小值开始并转到向量的最大值)。

timestep<-seq.POSIXt(strptime("2014-10-21 00:00:00","%Y-%m-%d %H:%M:%S"), strptime("2015-10-21 23:59:59","%Y-%m-%d %H:%M:%S"), timestep)
det_interval = data.frame(table(cut(dateseq, breaks = timestep, right=T, include.lowest=T)))

head(det_interval)
tail(det_interval)