For a questionnaire I want to make a copy of df1 where the following two things happen with column x:
Replace missing data of x (which is coded as 0) for '-1'. So all the 0 must become -1.
A specific part of x is coded in numbers instead of categories. I created a function to assign different categories to different values
categorise <- function(a_vector) { a_vector = case_when(
a_vector >= 0 & a_vector < 50 ~ 1,
a_vector >= 50 & a_vector < 500 ~ 2,
a_vector >= 500 & a_vector < 5000 ~ 3,
a_vector >= 5000 & a_vector < 50000 ~ 4,
a_vector >= 50000 & a_vector < 500000 ~ 5,
a_vector >= 500000 & a_vector < 5000000 ~ 6,
a_vector >= 5000000 & a_vector < 50000000 ~ 7,
a_vector >= 50000000 & a_vector < 500000000 ~ 8)
strong texta_vector }