Why does apply() return incorrect column types?
I've recently started using R and the apply() function is tripping me up. I'd appreciate help with this: is.numeric(iris$Sepal.Length) # returns TRUE is.numeric(iris$Sepal.Width) # returns TRUE is.numeric(iris$Petal.Length) # returns TRUE is.numeric(iris$Petal.Width) # returns TRUE but, apply(iris, 2, FUN = is.numeric) returns Sepal.Length Sepal.Width Petal.Length Petal.Width Species FALSE FALSE FALSE FALSE FALSE What's going on? They are all FALSE because apply() coerces iris to a matrix before it applies the is.numeric() function. From help(apply) regarding the first argument, X - If X is