0

I am looking for the shortest way to recode many variables in the same way.

For example I have data frame where columns a,b,c are names of items of survey and rows are observations.

d <- data.frame(a=c(1,2,3), b=c(1,3,2), c=c(1,2,1))

I want to change values of all observations for selected columns. For instance value 1 of column "a" and "c" should be replaced to string "low" and values 2,3 of these columns should be replaced to "high".

I do it often with many columns so I am looking for function which can do it in very simple way, like this:

recode2(data=d, columns=a,d, "1=low, 2,3=high").

Almost ok is function recode from package cars, but if I have 10 columns to recode I have to rewrite it 10 times and it is not as effective as I want.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12

0 Answers0