library(readr) 

# Function that takes in a dataset/matrix and returns the number of NA values per column
NAs <- function(dataset) {
  as.vector(apply(dataset, 2, function(x) length(which(is.na(x)))))
}

# This function does the same thing as the NAs function with the exception that it reads the given 
# file in small chunks, so that R won't run out of memory. Note: I counted the number of rows in each 
# training file beforehand and it is 1183748, which is why I chose 23 iterations.
AllNAs <- function(filename) {
  df <- read.csv(file=filename,nrows=50000, skip=0)
  tmp = NAs(df)
  for (i in 1:23){
    df <- read.csv(file=filename,nrows=50000, skip=i*50000)
    tmp = tmp + NAs(df)
  }
  return (tmp)
}

fname = "../input/train_numeric.csv"
totalNAs <- AllNAs(fname)

# save the headers in the headers variable
headers <- read.csv(file=fname, nrows=1, header=FALSE)

# what we have done here is to remove the headers of the columns that have more than 600000 NA values.
# finally, we print the column number and the names of the headers that have less than 600000 NA values.
goodHeaders = headers[-which(totalNAs>600000)]
for (i in 1:length(goodHeaders)) { 
    print(goodHeaders[i]) 
    print("", quote=FALSE)
}


# If you have any suggestions as to how to make this code faster, more efficient or really any 
# sort of constructive critisism please don't hesitate to comment. I'm very new at this.