I'm trying to perform a latent class analysis at the moment on a dataset. Most of the variables in the dataset are coded 1 to 10 on a likert scale e.g. 1 is least and 10 is most. I want to convert these variables so that 1:5 are grouped and labelled as 1 and then 6:10 are grouped and labelled as 2. I'm not sure if there is code that can do this?
I have tried recode(variable$data) but that does not seem to work.
Is there a command that I can use to recode the values?
As @ihecker mentioned, you can do something like the below:
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
x <- 1:10
dplyr::case_when(
x <= 5 ~ 1,
x >= 6 ~ 2
)
#> [1] 1 1 1 1 1 2 2 2 2 2
Here is an example of how you will retain it. You can call mutate which will then change or create a new column in your data frame. Here you see we create z based on column_a.