Consider that my dataset is large and more complicated (more columns and rows).
This would be a simpler set as an example:
A <- rep(NA,10)
B <- rep(2,10)
C <- rep(NA,10)
D <- rep('B',10)
E <- c('NA',rep('XY',9))
dat <- data.frame(A,B,C,D,E)
A B C D E
1 NA 2 NA B NA
2 NA 2 NA B XY
3 NA 2 NA B XY
4 NA 2 NA B XY
5 NA 2 NA B XY
6 NA 2 NA B XY
7 NA 2 NA B XY
8 NA 2 NA B XY
9 NA 2 NA B XY
10 NA 2 NA B XY
Variable A and Variabel B do not include any data. I would like to drop all variables from the data.frame that do include only NAs, so that the variables with content remain. dplyr solutions are welcome, but others as well.