r语言怎么把数据框中的所有数据转换成时间序列啊
问题描述:
导入右边这个数据库之后,用了ts函数转换成时间序列,想让数据变成从1945年1月到1950年12月的月度数据,但是用ts(test, start=(1945,1), frequent=12)后只能得到右边的结果…
答
使用ts函数转换为时间序列:
getwd()
df<-read.csv('r929.csv')
print(df)
a<-ts(df, start=c(1945,1),end=c(1945,4), frequency=12)
print(a)
运行结果:
v1 v2 v3 v4
Jan 1945 30.2 20.5 23.3 14.0
Feb 1945 22.0 15.6 17.5 40.1
Mar 1945 23.8 24.6 22.9 16.8
Apr 1945 44.5 22.7 70.2 56.0
...