我正在嘗試以一種方式清理資料集,其中我有一列日期,其中包含相應月份和相應月份的年降雪量。
我正在為此而苦苦掙扎,并尋求幫助。

而不是每個月的列,我希望它是我每年/每月有一列的地方,包括一個帶有相應年度降雪量的列。
SEASON JUL AUG SEP OCT NOV DEC JAN FEB MAR APR MAY JUN TOTAL
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1869-70 0 0 0 0 0 5.3 1.1 9.3 9.6 2.5 0 0 27.8
2 1870-71 0 0 0 0 0 3 15.9 12.1 0.1 2 0 0 33.1
3 1871-72 0 0 0 0 0.3 3.9 1.8 3 5.1 0 0 0 14.1
4 1872-73 0 0 0 0 3.5 27 10.6 18.8 0.4 0 0 0 60.3
5 1873-74 0 0 0 0 2 9.3 6.6 19 0 0 0 0 36.9
6 1874-75 0 0 0 0 0 10 14.5 4.5 15.3 13.5 0 0
uj5u.com熱心網友回復:
試試這個:讓我們假設你的資料框被稱為“df”!
library(dplyr)
df <- df %>% pivot_longer(cols = c(JUL:JUN)) %>% select(SEASON, name, value, TOTAL) %>% rename(MONTH = "name", VALUE = "value")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/343288.html
標籤:r
上一篇:使用摘要式身份驗證的HttpClient發布請求導致錯誤請求
下一篇:對生成的輸出表進行調整
