The greatest place to begin is with?str (). Let's create some data to look at various examples:
set.seed(3221) # This ensures that the example can be replicated exactly my.data - data.frame (y=rnorm(5), x1=c(1:5), x2=c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALS
The solution proposed by @Wilmer E Henao H is quite simple:
sapply(my.data, class) y x1 x2 X3 "numeric" "integer" "logical" "factor" sapply(my.data, class) y x1 x2 X3 "numeric" "integer" "logical" "factor"
When you use str(), you get that information as well as some extras (such the levels of your factors and the first few values of each variable):
'data.frame' str(my.data): 5 obs. of 4 variables:
num 1.03 1.599 -0.818 0.872 -2.682 $ y: num 1.03 1.599 -0.818 0.872 -2.682 $ y: num 1.03 1.599
$ int 1 2 3 4 5 $ x1: int 1 2 3 4 5 $ x1: int 1 2 3 4
$ x2: logi TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
$ X3: Factor with 5 levels "a," "b," "c," "d," and so on: 1, 2, 3, 4, and 5
@Gavin Simpson takes a similar method, but gives somewhat different facts.