我試圖在R中創建兩個連續變數--電價和可再生能源產量之間的聯合頻率分布表,對于某些范圍,例如使用10個20歐元的價格范圍和10個10.000-Wh的可再生能源發電量范圍。 我的資料看起來是這樣的:
structure(list(DATE =結構(c(18628。 18629, 18630。 18631, 18631,
18632, 18633, 18634。 18635, 18636。 18637, 18638。
18641, 18642, 18643。 18644, 18645。 18646, 18647)。 class = "Date"),
價格 = c(45.58041666667, 47。 11125, 43.4683333, 47.45791666667, 47.45791666667
50.89458333333, 52.84375, 44. 64375, 55.7233333, 51.64125,
51.9604166666667, 51.6475, 52. 468333333, 67.7625, 46.15916666667,
63.68875, 50.955, 53. 97583333333, 66.94625, 71. 73, 63.44583333
), RES = c(23534. 08, 21286. 57, 42159.53, 45660. 36, 36967.42,
33727.61, 45660. 92, 59931.54, 48146. 49, 48424.06, 60207.69,
45786.85, 38909. 96, 49843.98, 43003. 73, 41491, 41655.27,
42133.29, 31207.87, 36045. 62)),行。 names = c(NA。 20L), class = "data. frame")
我一直無法用某些頻率包構建這種表格,有人知道如何做嗎?請先謝謝你。
uj5u.com熱心網友回復:
資料:
df < -結構(list(DATE =結構(c(18628。 18629, 18630。 18631, 18631,
18632, 18633, 18634。 18635, 18636。 18637, 18638。
18641, 18642, 18643。 18644, 18645。 18646, 18647)。 class = "Date"),
價格 = c(45.58041666667, 47。 11125, 43.4683333, 47.45791666667, 47.45791666667
50.89458333333, 52.84375, 44. 64375, 55.7233333, 51.64125,
51.9604166666667, 51.6475, 52. 468333333, 67.7625, 46.15916666667,
63.68875, 50.955, 53. 97583333333, 66.94625, 71. 73, 63.44583333
), RES = c(23534. 08, 21286. 57, 42159.53, 45660. 36, 36967.42,
33727.61, 45660. 92, 59931.54, 48146. 49, 48424.06, 60207.69,
45786.85, 38909. 96, 49843.98, 43003. 73, 41491, 41655.27,
42133.29, 31207.87, 36045. 62)),行。 names = c(NA。 20L), class = "data. frame")
代碼:
# check min and max of your respective vector price and RES
# 使用切割來創建范圍。
df$priceRanges < - cut(df$price, seq(40, 80, by = 10))
df$RESRanges < - cut(df$RES, seq(20000。 70000。 通過= 10000))
# table the created variables with relative frequencies。
托普。 table(table(df[。 c("priceRanges"/span>。 "RESRanges")]))
## 1
# export as txt with rownames to working directory
新的<-道具。 table(table(df[, c("priceRanges"/span>。 "RESRanges")]))
write.table(new, file = "new. txt", sep = ","。 quote = FALSE, 行。 names = TRUE)。
## 2
# export as csv ...
write.csv2(new, file = "new. csv", quote = FALSE, row. names = TRUE)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/334047.html
標籤:
