I am trying to make a new column in my data.frame based on another column.
My data frame is called dat.cp2 and one column in it has a certain year from 1990-2017 Here you can see how my data looks. The "ar" column states a year.
I need to make a new column called "TB" with periods. e.g period one is 1990-1996 and i want that period to be called "TB1".. 1997-2003 is "TB2" etc. So for a person born in 1995 the new column says "TB1".
I tried:
dat.cp2 %>% mutate(TB =
case_when(ar <=1996 ~ "TB1",
ar >=1997&<=2003 ~ "TB2",
ar >=2004&<=2010 ~ "TB3",
ar >=2011 ~ "TB4")
But i get error message:
Error: unexpected '<=' in:
" case_when(ar <=1996 ~ "TB1",
ar >=1997&<="
I have tried looking for answers but can't find any.. Can anyone help?
dput()
and posting the output. – rjen&<=
is wrong for TB2 and TB3 It should bear >= 1997 & ar <= 2003
– akrun