Since data.frame is a list , you should use lapply or sapply :
sapply(someDf, is.logical) fac1 int char logi fac2 FALSE FALSE FALSE TRUE FALSE
The reason your code doesn't work is because apply needs a matrix as its argument and forces the matrix if you provide a data frame. Since a matrix can only contain elements of one class, your values ββare converted to character . Try:
as.matrix(someDf) fac1 int char logi fac2 [1,] "1" " 1" "a" " TRUE" "1" [2,] "1" " 2" "b" "FALSE" "1" [3,] "1" " 3" "c" " TRUE" "2" [4,] "2" " 4" "d" "FALSE" "2" [5,] "2" " 5" "e" " TRUE" "3" [6,] "2" " 6" "f" "FALSE" "3" [7,] "1" " 7" "g" " TRUE" "1" [8,] "1" " 8" "h" "FALSE" "1" [9,] "1" " 9" "i" " TRUE" "2" [10,] "2" "10" "j" "FALSE" "2" [11,] "2" "11" "k" " TRUE" "3" [12,] "2" "12" "l" "FALSE" "3"
source share