I have a matrix that I want to extract column names based on the value. In this case I want the name of any column that contains a value less than or equal to 2 (doesnt matter what row that value is located in).
set.seed(42)
DF <- matrix(sample(1:9,9),ncol=3,nrow=3)
DF <- as.data.frame.matrix(DF)
this is what I have tried, (it seems to work if there is only 1 row in the matrix)
test<-colnames(DF)[which(DF<=2),]
test would then represent the column names containing values <= 2