Red wine tasting

In this exercise, you will have a look at the distributions of ratings for red wines from four different countries. The data are already pre-loaded in a data frame called red_wine_data. Check out the data in order to get a feel for it before you begin!

To obtain a histogram for each type of red wine, you will need to first rearrange the data into subsets. Use the subset() command to do this. Given a data frame, this function returns a new data frame containing only the elements that satisfy some condition. For example, red_wine_data$condition == "France" returns only the subset of data pertaining to French red wines.

This exercise is part of the course

Intro to Statistics with R: Introduction

View Course

Exercise instructions

  • Inspect the red_wine_data data frame by printing it to the console.
  • Provide some summary statistics for red_wine_data using the describe() function.
  • Split the data frame into one subset per country, as instructed above.
  • Make four new variables that contain the Ratings data from each of the newly created subsets. Use the $ operator.
  • Code is provided for you to organize your histograms into a 2x2 matrix using the par() function. Don't change this.
  • Plot a histogram of the ratings for each country using hist(). Display them in the same order as you defined them. Give your histograms sensible titles and label the x-axes with "score"

Hands-on interactive exercise

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

## The data frame `red_wine_data` is already pre-loaded

# Print red_wine_data


# Print basic statistical properties of red_wine_data


# Split the data frame into subsets for each country
red_usa <- ___
red_france <- ___
red_australia <- ___
red_argentina <- ___

# Select only the Ratings variable for each subset
red_ratings_usa <- ___
red_ratings_france <- ___
red_ratings_australia <- ___
red_ratings_argentina <- ___
  
# Create a 2 by 2 matrix of histograms
par(mfrow = c(2, 2))
    
# Plot four histograms, one for each subset