10.2 Data Frame Features
The str() command is useful to see a listing of the variables and their variable types in the console.
The nrow() command shows the length of the data frame.
The ncol() command shows the number of columns in the data frame.
The rownames() or row.names() functions indicate the names of the rows. The quotes around the numbers show that the row names are characters, rather than an actual number.
The colnames() or names() functions indicate the names of the columns. Again, the quotes indicate that the names are character variables.
The typeof() function allows us to know what is the object type.
The class() function describes what is the object.
The attributes() function summarizes the column names, the row names, and the class of the object.
Using the data frame dat created in subsection 10.1, you can see the output produced from each of the statements below.
str(dat)
nrow(dat)
ncol(dat)
rownames(dat)
row.names(dat)
colnames(dat)
names(dat)
typeof(dat)
class(dat)
attributes(dat)
You can view the the top 6 rows by typing head(dat) or the bottom 6 rows by typing tail(dat).
head(dat)
tail(dat)
If your data frame is really large, either a lot of variables or observations, remember the options command to expand the printing in the Console Window that was introduced in subsection 2.5.
options(maxprint = 1000000)