1

I am trying to use the recode into function using expss. When I replicate the example illustrated in https://gdemin.github.io/expss/#example_of_data_processing_with_multiple-response_variables I notice the following behaviour: code including a do_if statement works perfect:

w = w %>%  do_if(cell == 1, 
    {recode(a1_1 %to% a1_6, other ~ copy) %into% (h1_1 %to% h1_6)})

Without the do_if statement

w = w %>% recode(a1_1 %to% a1_6, other ~ copy) %into% (h1_1 %to% h1_6)

an error is generated "Error: 'a1_1' not found".

Is this correct?

It would also be nice to transfer variabele labels to the newly created variables (cfr. mutate)

Thanks for any advice on how to use correctly.

1 Answers1

0

Inside do_if recode is evaluated in the context of the data.frame. When there is no context recode will be evaluated in the global environment. And it don't see a1_1,... variables in the data.frame. The good news is that there is a compute function for arbitrary operations on data.frames:

w = w %>%  
    compute({
         recode(a1_1 %to% a1_6, other ~ copy) %into% (h1_1 %to% h1_6)
    })

As for labels copying, you can use argument 'with_labels' = TRUE or an alias 'rec' which has 'with_labels' = TRUE by default:

w = w %>%  
    compute({
         rec(a1_1 %to% a1_6, other ~ copy) %into% (h1_1 %to% h1_6)
    })

Gregory Demin
  • 4,596
  • 2
  • 20
  • 20