I have in my data this column :
table(data$year)
2011 2012 2013 2014 2015 2016 2017 2018 2019
2 28 17 36 26 29 37 33 10
is.numeric(data$year)
[1] TRUE
I want to mutate with case_when with the following code :
data <- data %>%
mutate(periode_2a = case_when(
year >= 2011 && year <= 2013 ~ "2011-2013",
year >= 2014 && year <= 2015 ~ "2014-2015",
year >= 2016 && year <= 2017 ~ "2013-2017",
TRUE ~ "2018-2019"
))
Which i think is obvious : i want to make category of years.
I obtain that :
table(data$periode_2a)
2011-2013
218
I have try some other style :
> data <- data %>%
+ mutate(periode_2a = case_when(
+ year == 2011:2013 ~ "2011-2013",
+ year == 2014:2015 ~ "2014-2015",
+ year == 2016:2017 ~ "2013-2017",
+ TRUE ~ "2018-2019"
+ ))
or
> data <- data %>%
+ mutate(periode_2a = case_when(
+ year == "2011"|"2012"|"2013" ~ "2011-2013",
+ year == "2014"|"2015" ~ "2014-2015",
+ year == "2016"|"2017" ~ "2013-2017",
+ TRUE ~ "2018-2019"
+ ))
without success ...
What did i wrong ??
Thanks to all
&&
and replace with&
and in second, use%in%
instead of==
– akrun