I would like to create a loop to
- create a serie of variables a1-a17 to a given dataframe (df)
- assign values of variable C to a1-a17 based on the value of variable b.
I don't want to do this 17 times, please give me some advices to make them into a loop:
df$a1 <- ifelse(df$b ==1, df$c, NA )
df$a2 <- ifelse(df$b ==2, df$c, NA )
.
.
.
df$a16 <- ifelse(df$b ==16, df$c, NA )
df$a17 <- ifelse(df$b ==17 , df$c, NA )
thanks for any answers for a beginner!
Aucun commentaire:
Enregistrer un commentaire