I would like to iterate over columns in dataframe and for every column if the number of NAs is bigger than 50% of all entries I would like to remove that column from the dataframe. So far I have something like this but it doesn't work:
for (i in names(df_r)) {
if (sum(is.na(df_r[,i]))/length(df_r) > 0.5) {
df_r <- df_r[, -i]
}
}
I am more of a python guy and I am learning R so I might be mixing syntax here.