5.4 Inspecting data.frame objects
We’ve seen how str() can be useful to check the content and the structure of a data.frame. Here is a non-exhaustive list of functions to get a sense of the content/structure of the data.
- Size:
dim()- returns a vector with the number of rows in the first element, and the number of columns as the second element (the dimensions of the object)nrow()- returns the number of rowsncol()- returns the number of columns
- Content:
head()- shows the first 6 rowstail()- shows the last 6 rows
- Names:
names()- returns the column names (synonym ofcolnames()fordata.frameobjects)
rownames()- returns the row names
- Summary:
str()- structure of the object and information about the class, length and content of each column
summary()- summary statistics for each column
Note: most of these functions are “generic”, they can be used on other types of objects besides data.frame.