I spent a few hours trying to figure out why this loop isn't working. It keeps on printing '1'. The dataset used contains combinations of the 4 variables, though it seems the unsuccessful loop covers the first one only:
data$newcolumn <- for (newcolumn in 1:nrow(data))
{if(data$Male_exposure=="High" && data$Quality=="HighQ") {print(1)}
if (data$Male_exposure=="High"&& data$Quality=="LowQ") {print(2)}
if (data$Male_exposure=="Low"&& data$Quality=="HighQ") {print(3)}
if (data$Male_exposure=="Low"&& data$Quality=="LowQ") {print(4)}}
Why could that be the case?
Aucun commentaire:
Enregistrer un commentaire