What is the command to check which format a column within a dataframe is, i.e., numeric, char, factorial, etc.
I have searched this online; apparently I am using the wrong search terms.
What is the command to check which format a column within a dataframe is, i.e., numeric, char, factorial, etc.
I have searched this online; apparently I am using the wrong search terms.
Easy.
class(df$yourcol
#i.e.
df<-data.frame(matrix(1:4,2,2))
class(df$X2)
Edit
As Sotos commented above you can also do str(df)
which returns a class for all columns.
@CCurtis answer is correct, but you can also use the command sapply(df, class)
In the following example I use the diamonds dataset from the ggplot2 package.
library(ggplot2)
sapply(diamonds, class)
gives you the following output
$carat
[1] "numeric"
$cut
[1] "ordered" "factor"
$color
[1] "ordered" "factor"
$clarity
[1] "ordered" "factor"
$depth
[1] "numeric"
$table
[1] "numeric"
$price
[1] "integer"
$x
[1] "numeric"
$y
[1] "numeric"
$z
[1] "numeric"