I've a simple question which makes me weird this morning. How can I get a vector showing the classes of columns of a dataframe?
When I compute this I thought it should work, but it doesn't. I were even more surprised of the result and didn't understand the result.
Here is my example:
Example = data.frame(
Col1 = c(2,5,10),
Col2 = c("Hello", "I am a", "Factor"),
Col3 = c(T,F,T))
str(Example)
# 'data.frame': 3 obs. of 3 variables:
# $ Col1: num 2 5 10
# $ Col2: Factor w/ 3 levels "Factor","Hello",..: 2 3 1
# $ Col3: logi TRUE FALSE TRUE
So I have got a data frame with one numeric column, one factor column and one logical column and the result of the class()
command in the apply function is character
. Can anybody explain me why and how I can get a vector of the classes?
apply(Example, 2, class)
# Col1 Col2 Col3
# "character" "character" "character"