Creating season variable by month with dplyr in R

后端 未结 3 543
渐次进展
渐次进展 2021-01-20 05:12

I have a dataset that has a variable called month, which each month as a character. Is there a way with dplyr to combine some months to create a season variable? I have trie

3条回答
  •  耶瑟儿~
    2021-01-20 05:26

    When there are multiple key/value, we can do a join with a key/val dataset

    keyval <- data.frame(month = month.abb, 
          season = rep(c("Winter", "Spring", "Summer", "Fall"), each = 3),
          stringsAsFactors = FALSE)
    
    left_join(data, keyval)
    

提交回复
热议问题