O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the str() function for an overview of a data frame

The str() function gives a concise view of a data frame. In fact, we can use it to see the underlying structure of any arbitrary R object. The following commands and results show that the str() function tells us the type of the object whose structure we seek. It also tells us about the type of each of its component objects, along with an extract of some values. It can be very useful for getting an overview of a data frame.

> str(auto)  'data.frame': 398 obs. of  9 variables:    $ No          : int  1 2 3 4 5 6 7 8 9 10 ...    $ mpg         : num  28 19 36 28 21 23 15.5 32.9 16 13 ...    $ cylinders   : Factor w/ 5 levels "3cyl","4cyl",..: 2 1 2 2 4       2 5 2 4 5 ...  $ displacement: num 140 70 107 97 199 115 304 119 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required