Get Started

Have a look at the structure

Another method that is often used to get a rapid overview of your data is the function str(). The function str() shows you the structure of your dataset. For a data frame it tells you:

  • The total number of observations (e.g. 32 car types)
  • The total number of variables (e.g. 11 car features)
  • A full list of the variables names (e.g. mpg, cyl … )
  • The data type of each variable (e.g. num)
  • The first observations

Applying the str()] function will often be the first thing that you do when receiving a new dataset or data frame. It is a great way to get more insight in your dataset before diving into the real analysis.

This is a part of the course

“Introduction to R”

View Course

Exercise instructions

Investigate the structure of mtcars. Make sure that you see the same numbers, variables and data types as mentioned above.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Investigate the structure of mtcars

This exercise is part of the course

Introduction to R

BeginnerSkill Level
4.7+
595 reviews

Master the basics of data analysis in R, including vectors, lists, and data frames, and practice R with real data sets.

Most datasets you will be working with will be stored as data frames. By the end of this chapter, you will be able to create a data frame, select interesting parts of a data frame, and order a data frame according to certain variables.

Exercise 1: What's a data frame?Exercise 2: Quick, have a look at your datasetExercise 3: Have a look at the structure
Exercise 4: Creating a data frameExercise 5: Creating a data frame (2)Exercise 6: Selection of data frame elementsExercise 7: Selection of data frame elements (2)Exercise 8: Only planets with ringsExercise 9: Only planets with rings (2)Exercise 10: Only planets with rings but shorterExercise 11: SortingExercise 12: Sorting your data frame

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free