0

I am struggling with those for loops because the dataframe is quite large (250 000 rows) and it takes a long long time and I don't how to put apply function in this. Can you please help me??

for(j in 1:nrow(df) ){
  if(is.na(df[j, 5]) == FALSE ) {
    for (k in 1:nrow(d)f){
      if(d[df,1] == df[j,1] && is.na(df[k,5]) == TRUE ){
        df[k,5] = df[j,5]
      }
    }
  } 
}

Thank you so much!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Could you please provide `dput(head(df))` along with your question? – MKR May 19 '18 at 18:08
  • Additionally, you'll need to explain what you're trying to do here. The inner loop is ... well ... overwriting `df[k,5]` a LOT, which does not immediately seem to make sense. (On first glance, though, it looks like imputation of missing values, for which a search for `R impute` might be meaningful and sufficient.) – r2evans May 19 '18 at 18:47
  • @DCaroline_las: you need to post the output from R not the screenshot. See more here [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Tung May 19 '18 at 20:33
  • If df is a dataframe, what is the meaning of d[df,1] in your second if statement? – Katia May 20 '18 at 02:51

0 Answers0