予加载使用CSV文件:保存XTS对象作为csv文件
data = read.csv(file="/home/stefanos/R/data_frames_new/temp2.csv", header=TRUE, sep=",")
前4行temp2.csv文件是:
nodeId,battery,date,idHistoric,temperature,longitude,latitude
3,78.00,2013-04-01 00:04:03,30163676,13.74,-3.80176,43.46192
3,78.00,2013-04-01 00:09:01,30164278,13.67,-3.80176,43.46192
3,78.00,2013-04-01 00:13:59,30164875,13.67,-3.80176,43.46192
欲由节点ID组和它每15分钟查找一次温度的平均值。所以,I型:
df <- xts(x = data[, c("nodeId", "battery", "idHistoric", "temperature", "longitude", "latitude")], order.by = as.POSIXct(data[, "date"], tz = "GMT", format = "%Y-%m-%d %H:%M:%S"))
然后:
df2 <- by(df,df$nodeId,function(x){
ends <- endpoints(x, on = "minutes", k = 15)
xx <- period.apply(x, ends, mean)
})
我的问题是,我不能写DF2为csv文件。我还没有能够这样做。 当我在屏幕上我看到了以下结构打印DF2:
/*********************************************/
INDICES: 3
nodeId battery idHistoric temperature longitude latitude
2013-04-01 00:13:59 3 78.00000 30164276 13.69333 -3.80176 43.46192
2013-04-01 00:28:54 3 79.00000 30166075 13.78000 -3.80176 43.46192
[...]
------------------------------------------------------------
INDICES: 4
nodeId battery idHistoric temperature longitude latitude
2013-04-01 00:13:07 4 87.00000 30164172 14.42667 -3.80098 43.46199
2013-04-01 00:28:01 4 87.33333 30165964 14.49000 -3.80098 43.46199
------------------------------------------------------------
INDICES: 5
nodeId battery idHistoric temperature longitude latitude
2013-04-01 00:13:31 5 83.00000 30164224 13.84667 -3.80058 43.46203
2013-04-01 00:28:26 5 83.66667 30166018 14.06000 -3.80058 43.46203
------------------------------------------------------------
INDICES: 6
nodeId battery idHistoric temperature longitude latitude
2013-04-01 00:12:52 6 78.00000 30164128 13.99667 -3.79979 43.46212
2013-04-01 00:28:52 6 79.00000 30165983 13.97333 -3.79979 43.46212
/*********************************************/
所以,我怎样才能将其保存在CSV?
'df2'是类“by”的列表。因为它是一个列表,你应该可以用'do.call(“rbind”,df2)'把它变成一个data.frame。但没有一个可重复的例子,我无法测试... – Roland