0
我需要收集和轉置數據幀中的數據,小時值應該在一列中。第一列應該是帶小時和秒轉置小時值的日期。拆分,轉置和收集數據幀
樣本數據:
structure(list(Year = c(2016L, 2016L), JDay = 1:2, Hour_1 = c(2.59,
5.95), Hour_2 = c(2.19, 5.84), Hour_3 = c(1.84, 5.75), Hour_4 = c(1.51,
5.66), Hour_5 = c(1.21, 5.58), Hour_6 = c(0.94, 5.5), Hour_7 = c(0.69,
5.43), Hour_8 = c(0.45, 5.37), Hour_9 = c(0.23, 5.31), Hour_10 = c(2.18,
6.19), Hour_11 = c(4.39, 7.16), Hour_12 = c(6.29, 8), Hour_13 = c(7.76,
8.65), Hour_14 = c(8.68, 9.06), Hour_15 = c(9, 9.2), Hour_16 = c(8.68,
9.06), Hour_17 = c(7.76, 8.65), Hour_18 = c(7.8, 8.52), Hour_19 = c(7.21,
7.57), Hour_20 = c(6.85, 6.99), Hour_21 = c(6.59, 6.57), Hour_22 = c(6.39,
6.25), Hour_23 = c(6.22, 5.98), Hour_24 = c(6.08, 5.75)), .Names = c("Year",
"JDay", "Hour_1", "Hour_2", "Hour_3", "Hour_4", "Hour_5", "Hour_6",
"Hour_7", "Hour_8", "Hour_9", "Hour_10", "Hour_11", "Hour_12",
"Hour_13", "Hour_14", "Hour_15", "Hour_16", "Hour_17", "Hour_18",
"Hour_19", "Hour_20", "Hour_21", "Hour_22", "Hour_23", "Hour_24"
), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"
使用的收集只是給我的,爲了所有Hour_1值...
gather(OP_daily[, c(5:28)], time,temp, Hour_1:Hour_24)
輸出示例:
date temp
2016-1-1 1:00 2.59
2016-1-1 2:00 2.19
謝謝你@P拉波因特,但我需要包含每小時每一行轉成一個一天,等等。 1點24分的時間是第一天,依此類推。 –
@m_c你可以在你的問題中添加所需的結果作爲表格嗎? –
就是這樣做的,看來還不夠清楚。你的解決方案給了我上面的代碼,這就是爲什麼我在這裏發佈一個問題。 –