mercredi 21 juin 2017

For loop output not as expected

I have the following nested for loop with a conditional, but it seems, the conditional is not regarded.

i = 1
for(fa in c(1, 2, 3, 4, 5, 6, 8, 9, 11)){
  for(wz in c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "N", "O", "P", "Q", "R", "S", "U")){
    avg_fzg <- fzg_aktiv_wv[fzg_aktiv_wv$K01 == fa & fzg_aktiv_wv$K19b == wz, c("K00", "K01", "K31c", "K34c")]
    avg_fahrten <- fzg_fahrten_merge
    avg_fahrten <- avg_fahrten[avg_fahrten$K01 == fa & avg_fahrten$K19b == wz & avg_fahrten$F15 != -1, c("K00", "K01", "K19b", "F14", "F15", "F04a")]
    avg_fahrten <- avg_fahrten[!duplicated(avg_fahrten),]

    if(length(avg_fzg$K01 >= 10)){
      print(length(avg_fzg$K01))
      Fzg_WZ_avg[i,1] <- median(avg_fzg$K31c)
      Fzg_WZ_avg[i,2] <- median(avg_fzg$K34c)
      Fzg_WZ_avg[i,3] <- median(avg_fahrten$F14)
      Fzg_WZ_avg[i,4] <- median(avg_fahrten$F15)
      Fzg_WZ_avg[i,5] <- median(avg_fahrten$F04a)


    }

  i <- i + 1
  } 
}

The print statement was for me to check, that length(avg$K01) is working the way I want it to - and it does, yet everything inside the conditional is executed.

Help is really appreciated! Thanks.

Aucun commentaire:

Enregistrer un commentaire