R:使用时间索引将mts转换为非时间序列数据帧的最佳方式 [英] R: Best way to convert a mts to a non-time series dataframe with time indexes
本文介绍了R:使用时间索引将mts转换为非时间序列数据帧的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下方法将mts数据集转换为具有时间索引列的数据框。有没有一个更优雅的方法来做到这一点?
z< - ts(matrix(rnorm(300) ),start = c(1961,1),frequency = 12)
YM <-cbind(Year = as.numeric(floor(time(z))),Month = as.numeric(cycle(z) )
z< -cbind(as.data.frame(YM),as.data.frame(z))
str(z)
解决方案
尝试这样:
data.frame(Year = c(floor(time(z)+ .01)),Month = c(cycle(z)),z)
/ pre>
或
as.data.frame(cbind Year = floor(time(z)+ .01),Month = cycle(z),z))
I'm currently using the following method to convert a mts dataset to a data frame with time indexes as columns. Is there a more elegant way to do this?
z <- ts(matrix(rnorm(300), 100, 3), start=c(1961, 1), frequency=12) YM<-cbind(Year=as.numeric(floor(time(z))),Month=as.numeric(cycle(z))) z<-cbind(as.data.frame(YM),as.data.frame(z)) str(z)
解决方案Try this:
data.frame(Year = c(floor(time(z) + .01)), Month = c(cycle(z)), z)
or
as.data.frame(cbind(Year = floor(time(z) + .01), Month = cycle(z), z))
这篇关于R:使用时间索引将mts转换为非时间序列数据帧的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文