I have a data frame where all the variables are of character type. Many of the columns are completely empty, i.e. only the variable headers are there, but no values. Is ther
You can do either of the following:
emptycols <- sapply(df, function (k) all(is.na(k))) df <- df[!emptycols]
or:
emptycols <- colSums(is.na(df)) == nrow(df) df <- df[!emptycols]
If by empty you mean they are "", the second approach can be adapted like so:
""
emptycols <- colSums(df == "") == nrow(df)