15.2 Getting Information About a Data Structure

15.2.1 Problem

You want to find out information about an object or data structure.

15.2.2 Solution

Use the str() function:

This tells us that ToothGrowth is a data frame with three columns, len, supp, and dose. len and dose contain numeric values, while supp is a factor with two levels.

Another useful function is the summary() function:

Instead of showing you the first few values of each column as str() does, summary() provides basic descriptive statistics (the minimum, maximum, median, mean, and first & third quartile values) for numeric variables, and tells you the number of values corresponding to each character value or factor level if it is a character or factor variable.