r - how to determine season dry or rainy in temporal analysis using R?
问题描述
I have the data temporal of temperature, i would like determinate if date be to season dry or rainy.
In my coutry the season dry start in May up to October, and season rainy start in November up to April.
Would be possible create a column with this information in package dplyr ou other?
my data-frame in:
sample_station <-c('A','A','A','A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B','B','B','C','C','C','C','C','C','C','C','C','C','A','B','C','A','B','C')
Date_dmy <-c('01/01/2000','08/08/2000','16/03/2001','22/09/2001','01/06/2002','05/01/2002','26/01/2002','16/02/2002','09/03/2002','30/03/2002','20/04/2002','04/01/2000','11/08/2000','19/03/2001','25/09/2001','04/06/2002','08/01/2002','29/01/2002','19/02/2002','12/03/2002','13/09/2001','08/01/2000','15/08/2000','23/03/2001','29/09/2001','08/06/2002','12/01/2002','02/02/2002','23/02/2002','16/03/2002','06/04/2002','01/02/2000','01/02/2000','01/02/2000','02/11/2001','02/11/2001','02/11/2001')
Temperature <-c(17,20,24,19,17,19,23,26,19,19,21,15,23,18,22,22,23,18,19,26,21,22,23,27,19,19,21,23,24,25,26,29,30,21,25,24,23)
df<-data.frame(sample_station, Date_dmy, Temperature)
解决方案
One option is to extract the month
after converting to Date
class, create a condition in case_when
to return 'dry', 'rainy' based on the values of 'Month' column
library(dplyr)
library(lubridate)
df <- df %>%
mutate(Month = month(dmy(Date_dmy)),
categ = case_when(Month %in% 5:10 ~ 'dry', TRUE ~ 'rainy'))
推荐阅读
- database - 指标收集和分析架构
- html - 寻找 flex 的替代品
- javascript - 我应该在谷歌图表代码中调整什么来摆脱一些属性?(javascript)
- electron - Ubunut 17.10 上未显示电子托盘图标
- python - 将单个记录插入 HIVE Orc 表时,Pyspark spark.sql 很慢
- reactjs - 对象的属性类型是必需的还是空的?
- kubernetes - 将 Grafana 指标与不匹配的标签相结合
- vue.js - vue-cli:尝试从资产文件夹加载图像时出错
- python - 使用 for 循环创建多个注释
- c# - 将整个 DataGridView 保存为图像