Hi,
Welcome to the RStudio community!
Here is one example how to do this:
set.seed(4000)
#Generate data
myData = matrix("", nrow = 200, ncol = 20)
myData[sample(1:4000, 10)] = 1
myData = as.data.frame(myData)
#Find empty columns
result = apply(myData, 2, function(myCol){
sum(myCol == "1") > 0
})
names(result)[result == F]
#> [1] "V1" "V3" "V6" "V8" "V9" "V10" "V12" "V14" "V15" "V16" "V17"
Created on 2020-09-09 by the reprex package (v0.3.0)
I assumed that the empty values in your data frame were in text format "", as I didn't nee any NA or 0 in your sample. You can change this in the sum(myCol == "1") > 0
part if needed.
The trick is to do an apply by column and check for every column if it contains the value of interest (myCol == "1"). This will output a TRUE every time it is. TRUE = 1, so if we sum them up and the total column sum = 0, there are no values of interest.
Hope this helps,
PJ