I need to create a group of variables based on the same criteria. The first variable is named location1, and is created based on other variables (var1, var2, var3) as:
location1[var1==1] <- 1
location1[var2==1] <- 2
location1[var3==1] <- 3
...
location2[var1==1] <- 1
location2[var2==1] <- 2
location2[var3==1] <- 3
I have 100 location variable to create, location1 to location100, all using the same criteria based on var1,var2, var3 as shown here. Instead of typing it 100 times, which is very silly, how can I simply the code? var1, var2, var3 are dichotomous 1/0 values.
location1andlocation2-- the code you share for them is identical. - Gregor Thomas