lundi 31 octobre 2016

for loop and if loop in R. Reference/print other column

df <-

      Name      DDay
1    Item1      5
2    Item2      3
3    Item3      3
4    Item4      1
5    Item5      1
6    Item6      1

Logic is:
For (i in seq(from=0, to=5, by=1){
If Dday == i
Print Corrensponding Name (Targets)

I've tried

for (i in seq(from=0, to=5, by=1)){
if(df$Dday == i){
print(df$Name)
}

Full of errors. How can I write this logic in R code?

Thank you.

Aucun commentaire:

Enregistrer un commentaire