I have a matrix as like this
structure(list(Item = structure(c(3L, 1L, 4L, 2L), .Label = c("boat",
"bus ", "Car", "jeep"), class = "factor"), Cost = structure(c(3L,
1L, 2L, 4L), .Label = c("E.02", "E0.23", "E2.03", "E5.60"), class = "factor"),
BMW = c(0, 2.5, 12, 0.089), VW = c(0.56, 4.56, 0, 0.054),
Bens = c(0.06, 5.01, 4.57, 0), Pet = c(0.02, 5.31, 0.36,
45)), class = "data.frame", row.names = c(NA, -4L))
I need to remove columns which have zero. I tried with apply
row_sub = apply(data, 1, function(row) all(row !=0 ))
data[row_sub,]
But it is not working
Expected output
Item Cost BMW VW Bens Pet
boat E.02 2.5 4.56 5.01 5.31