我有一个动物园对象,目的是将数据转换为data.frame。
#CODE
#ZOO OBJECT
class(DATA_1ab)
#[1] "zoo"
#CONVERTING INTO DATA FRAME
TEST1<-data.frame(coredata(DATA_1ab))
class(TEST1)
#[1] "data.frame"
#NEW DATA FRAME
TEST1
SALES REVENUE
1 369.1 119.4
4 595.2 123.4
9 675.2 144.7
13 383.7 498.8
18 184.2 647.1
23 279.4 145.1
将Zoo对象转换为data.frame之后,我还有其他问题。即前列(SALES列)的增长计划异常(例如1,4,9,13,18,23等),所以我的问题是如何解决此问题并获取具有正常增长计划的新数据框架(例如1,2, 3,4,5,6)如下表所示?我问是因为我想继续将此data.frame放入ts对象,依此类推...
SALES REVENUE
1 369.1 119.4
2 595.2 123.4
3 675.2 144.7
4 383.7 498.8
5 184.2 647.1
6 279.4 145.1
具有dput函数的动物园对象(DATA_1ab)的数据示例
structure(c(369.1, 595.2, 675.2, 383.7, 184.2, 279.4, 266.9,
133.2, 419.7, 281.2, 276.5, 141.5, 298.2, 321.4, 298.1, 141.5,
.5,
119.4, 133, 405.4, 298.1, 57.8, 168.6, 435.3, 596, 136.6, 52.1,
151.9, 542.9, 151.4, 188.2, 35.6, 229.7, 517.7, -37.9, 94.9,
78.8, 658.9, 54.1, 156.8, 144.6, 649.4, 214.7, 379.6, 31.4), .Dim = c(157L,
2L), .Dimnames = list(c("1", "4", "9", "13", "18", "23", "28",
"33", "38", "43", "48", "53", "58", "63", "68", "73", "78", "82",
"86", "91", "96", "100", "105", "110", "114", "119", "124", "128",
"133", "138", "143", "147", "152", "157", "162", "167", "171",
"176", "181", "186", "191", "195", "200", "204", "209", "214",
"2016.02", "2016.03", "2016.04", "2016.05", "2016.06", "2016.07",
"2016.08", "2016.09", "2016.10", "2016.11", "2016.12", "2016.13",
"2016.14", "2016.15", "2016.16", "2016.17", "2016.18", "2016.19",
"2016.20", "2016.21", "2016.22", "2016.23", "2016.24", "2016.25",
"2016.26", "2016.27", "2016.28", "2016.29", "2016.30", "2016.31",
"2016.32", "2016.33", "2016.34", "2016.35", "2016.36", "2016.37",
"2016.38", "2016.39", "2016.40", "2016.41", "2016.42", "2016.43",
"2016.44", "2016.45", "2016.46", "2016.47", "2016.48", "2016.49",
"2016.50", "2016.51", "2016.52", "2017.01", "2017.02", "2017.03",
"2017.04", "2017.05", "2017.06", "2017.07", "2017.08", "2017.09",
"2017.10", "2017.11", "2017.12", "2017.13", "2017.14", "2017.15",
"2017.16", "2017.17", "2017.18", "2017.19", "2017.20", "2017.21",
"2017.22", "2017.23", "2017.24", "2017.25", "2017.26", "2017.27",
"2017.28", "2017.29", "2017.30", "2017.31", "2017.32", "2017.33",
"2017.34", "2017.35", "2017.36", "2017.37", "2017.38", "2017.39",
"2017.40", "2017.41", "2017.42", "2017.43", "2017.44", "2017.45",
"2017.46", "2017.47", "2017.48", "2017.49", "2017.50", "2017.51",
"2017.52", "2018.01", "2018.02", "2018.03", "2018.04", "2018.05",
"2018.06", "2018.07", "2018.08", "2018.09", "2018.10", "2018.11",
"2018.12", "2018.13", "2018.14", "2018.15", "2018.16", "2018.17",
"2018.18", "2018.19", "2018.20", "2018.21", "2018.22", "2018.23",
"2018.24", "2018.25", "2018.26", "2018.27", "2018.28", "2018.29",
"2018.30", "2018.31", "2018.32", "2018.33", "2018.34", "2018.35",
"2018.36", "2018.37", "2018.38", "2018.39", "2018.40", "2018.41",
"2018.42", "2018.43", "2018.44", "2018.45", "2018.46", "2018.47",
"2018.48", "2018.49", "2018.50", "2018.51", "2018.52", "2018.53"
), class = "zoo")
下面是转换为ts对象。
#CONVERTING INTO TS OBJECT
WEEKLY_TS_REVENUES<-ts(TEST1,start=c(2016,1),frequency = 52)
WEEKLY_TS_REVENUES
Time Series:
Start = c(2016, 1)
End = c(2019, 1)
Frequency = 52
SALES REVENUE
2016.000 369.1 119.4
2016.019 595.2 123.4
2016.038 675.2 144.7
2016.058 383.7 498.8
2016.077 184.2 647.1
2016.096 279.4 145.1
ts对象的第一列仍然不规则。