Search code examples
rexpss

EXPSS: Is there a way to add value labels for multiple columns without having to list each of them?


Want to add the same value labels to multiple columns using expss but there is too many to list.

Am looking for something like this but for a range of variables instead (e.g., for q1-q30)

val_lab(df[c("q1", "q2", "q6","q30")]) <- c("Awful"=1, "Bad"=2, "Ok"=3, "Good"=4, "Great"=5) 

Some codes I tried but did not work

val_lab(df[c("q1" %to% "q30")]) <- c("Awful"=1, "Bad"=2, "Ok"=3, "Good"=4, "Great"=5) 
val_lab(df[c('q1' %to% 'q30')]) <- c("Awful"=1, "Bad"=2, "Ok"=3, "Good"=4, "Great"=5) 
val_lab(df$q1 %to% df$q30) <- c("Awful"=1, "Bad"=2, "Ok"=3, "Good"=4, "Great"=5) 

Is there anyway around this? Thanks!


Solution

  • The code below set value label for range of variables.

    mtcars = mtcars %>% 
        let(
            (vs %to% carb) := set_val_lab(vs %to% carb, 
                                          c("one" = 1)
                                          )
            )