Get startedGet started for free

What's a data frame?

You may remember from the chapter about matrices that all the elements that you put in a matrix should be of the same type. Back then, your dataset on Star Wars only contained numeric elements.

When doing a market research survey, however, you often have questions such as:

  • 'Are you married?' or 'yes/no' questions (logical)
  • 'How old are you?' (numeric)
  • 'What is your opinion on this product?' or other 'open-ended' questions (character)

The output, namely the respondents' answers to the questions formulated above, is a dataset of different data types. You will often find yourself working with datasets that contain different data types instead of only one.

A data frame has the variables of a dataset as columns and the observations as rows. This will be a familiar concept for those coming from different statistical software packages such as SAS or SPSS.

This exercise is part of the course

Introduction to R

View Course

Exercise instructions

Submit the answer. The data from the built-in example data frame mtcars will be printed to the console.

Hands-on interactive exercise

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

# Print out built-in R data frame
mtcars 
Edit and Run Code