I have a number of variables with the same name but different suffix. For example, var1, var2, var3,var4,var5, var6... and so on. Each of these variables has random sequence of 0, 1, 2. Using these variables, I am trying to create a new variable called "testvariable." If any of the already existing variables has 1, I will give "testvariable" 1. If they have 0 or 2, I will assign 0.
Is there a simple loop and/or ifelse statement I can use to create this variable? My real data is a lot more complex than this, so I don't want to copy and paste each individual variable and values.
Edit: This is for R.
Aucun commentaire:
Enregistrer un commentaire