0
我想聚集在數據框中的一堆數據。但我使用該方法生成錯誤:與cbind聚合產生一個錯誤
錯誤[.default
(XJ,I):無效標式「封閉」
我怎樣才能糾正下面的代碼?
代碼:
agpowerDMWh<-aggregate(cbind(MW, DollarsPerMWh)~Date + HourEnding + DateDateHE + Season + MonthYear + Year + Month + Day + Weekday + IsWorkDayTSX + isPeak + isExtendedPeak + isSuperPeak , data=df, mean, na.rm=TRUE)
的樣本數據:
df<-structure(list(DateTime = structure(c(1325402100, 1325403000,
1325403900, 1325404800, 1325405700, 1325406600, 1325407500, 1325408400,
1325409300, 1325410200, 1325411100, 1325412000, 1325412900, 1325413800,
1325414700, 1325415600, 1325416500, 1325417400, 1325418300, 1325419200,
1325420100, 1325421000, 1325421900, 1325422800, 1325423700, 1325424600,
1325425500, 1325426400, 1325427300, 1325428200, 1325429100, 1325430000,
1325430900, 1325431800, 1325432700, 1325433600, 1325434500, 1325435400,
1325436300, 1325437200, 1325438100, 1325439000, 1325439900, 1325440800,
1325441700, 1325442600, 1325443500, 1325444400), class = c("POSIXct",
"POSIXt"), tzone = ""), MW = c(0.75636, 0.73304, 0.75504, 0.74624,
0.78628, 0.7832, 0.77176, 0.77968, 0.76516, 0.80168, 0.77, 0.7986,
0.77528, 0.7722, 0.78364, 0.77352, 0.72732, 0.75196, 0.73656,
0.72336, 0.75064, 0.737, 0.74008, 0.81752, 0.81136, 0.77924,
0.79156, 0.79024, 0.78848, 0.78056, 0.79376, 0.76824, 0.8096,
0.77, 0.78716, 0.75372, 0.737, 0.72776, 0.7304, 0.7018, 0.69652,
0.71192, 0.6952, 0.70752, 0.67804, 0.71808, 0.67584, 0.68904),
DollarsPerMWh = c(40.26, 40.26, 40.26, 40.26, 34.936, 34.936,
34.936, 34.936, 32.714, 32.714, 32.714, 32.714, 27.346, 27.346,
27.346, 27.346, 26.411, 26.411, 26.411, 26.411, 26.4, 26.4,
26.4, 26.4, 26.4, 26.4, 26.4, 26.4, 25.927, 25.927, 25.927,
25.927, 26.785, 26.785, 26.785, 26.785, 24.464, 24.464, 24.464,
24.464, 18.81, 18.81, 18.81, 18.81, 18.315, 18.315, 18.315,
18.315), minute = c(15, 30, 45, 0, 15, 30, 45, 0, 15, 30,
45, 0, 15, 30, 45, 0, 15, 30, 45, 0, 15, 30, 45, 0, 15, 30,
45, 0, 15, 30, 45, 0, 15, 30, 45, 0, 15, 30, 45, 0, 15, 30,
45, 0, 15, 30, 45, 0), hour = c(0, 0, 0, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7,
7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11,
11, 11, 12), Date = structure(c(15340, 15340, 15340, 15340,
15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340,
15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340,
15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340,
15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340,
15340, 15340, 15340, 15340, 15340, 15340, 15340, 15340), class = "Date"),
HourEnding = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9,
9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12),
DateDateHE = c("2012-01-01 HE1", "2012-01-01 HE1", "2012-01-01 HE1",
"2012-01-01 HE1", "2012-01-01 HE2", "2012-01-01 HE2", "2012-01-01 HE2",
"2012-01-01 HE2", "2012-01-01 HE3", "2012-01-01 HE3", "2012-01-01 HE3",
"2012-01-01 HE3", "2012-01-01 HE4", "2012-01-01 HE4", "2012-01-01 HE4",
"2012-01-01 HE4", "2012-01-01 HE5", "2012-01-01 HE5", "2012-01-01 HE5",
"2012-01-01 HE5", "2012-01-01 HE6", "2012-01-01 HE6", "2012-01-01 HE6",
"2012-01-01 HE6", "2012-01-01 HE7", "2012-01-01 HE7", "2012-01-01 HE7",
"2012-01-01 HE7", "2012-01-01 HE8", "2012-01-01 HE8", "2012-01-01 HE8",
"2012-01-01 HE8", "2012-01-01 HE9", "2012-01-01 HE9", "2012-01-01 HE9",
"2012-01-01 HE9", "2012-01-01 HE10", "2012-01-01 HE10", "2012-01-01 HE10",
"2012-01-01 HE10", "2012-01-01 HE11", "2012-01-01 HE11",
"2012-01-01 HE11", "2012-01-01 HE11", "2012-01-01 HE12",
"2012-01-01 HE12", "2012-01-01 HE12", "2012-01-01 HE12"),
Season = c("Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter", "Winter", "Winter", "Winter", "Winter", "Winter",
"Winter"), MonthYear = structure(c(2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012), class = "yearmon"), Year = c(2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012,
2012, 2012, 2012, 2012, 2012, 2012, 2012), Month = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1), Day = c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Weekday = c("Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunday",
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday"), IsWorkDayTSX = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE), isPeak = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), isExtendedPeak = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1), isSuperPeak = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0)), .Names = c("DateTime", "MW", "DollarsPerMWh",
"minute", "hour", "Date", "HourEnding", "DateDateHE", "Season",
"MonthYear", "Year", "Month", "Day", "Weekday", "IsWorkDayTSX",
"isPeak", "isExtendedPeak", "isSuperPeak"), row.names = c(NA,
48L), class = "data.frame")
感謝您檢查我。我想知道爲什麼我得到一個錯誤。 – user2946746