I have a dataframe where some of the values are NULL or Empty. I would like to remove these columns in which all values are NULL or empty. Columns should be removed from the dataframe, do not hidden only.
My head(df) looks like data=
VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7
1 2R+ 52 1.05 0 0 30
2 2R+ 169 1.02 0 0 40
3 2R+ 83 NA 0 0 40
4 2R+ 98 1.16 0 0 40
5 2R+ 154 1.11 0 0 40
6 2R+ 111 NA 0 0 15
The dataframe contains more than 200 variables, variables are empty and zero values do not occur sequentially.
I tried to estimate the average Col and select the column is Null or empty, by analogy with the removal of "NA" (see here), but it does not work.
df <- df[,colSums(is.na(df))<nrow(df)]
I got an error : 'x' must be an array of at least two dimensions
Can anyone give me some help? Thanks!