I have several columns in which certain numbers correspond with different values. I would like to replace them only in the first 3 columns.
A1 A2 A3 A4 A5
1 3 NA 5 2
1 2 1 2 1
3 NA NA 1 8
2 1 NA 1 12
1=cat
2=dog
3=rabbit
so I would like the output to be:
A1 A2 A3 A4 A5
cat rabbit NA 5 2
cat dog cat 2 1
rabbit NA NA 1 8
dog cat NA 1 12
I know how to replace the numbers in individual columns, but I would like to learn an easier way to do many at once. Thank you!
df[1:3] <- lapply(df[1:3], function(i) fun_to_replace...)