Skip to content

Latest commit

 

History

History
116 lines (81 loc) · 3.42 KB

File metadata and controls

116 lines (81 loc) · 3.42 KB

title : Insert the chapter title here description : Insert the chapter description here attachments : slides_link : https://s3.amazonaws.com/assets.datacamp.com/course/teach/slides_example.pdf

--- type:MultipleChoiceExercise lang:r xp:50 skills:1 key:146bb9121e

A really bad movie

Have a look at the plot that showed up in the viewer to the right. Which type of movie has the worst rating assigned to it?

*** =instructions

  • Adventure
  • Action
  • Animation
  • Comedy

*** =hint Have a look at the plot. Which color does the point with the lowest rating have?

*** =pre_exercise_code

# The pre exercise code runs code to initialize the user's workspace.
# You can use it to load packages, initialize datasets and draw a plot in the viewer

movies <- read.csv("http://s3.amazonaws.com/assets.datacamp.com/course/introduction_to_r/movies.csv")

library(ggplot2)

ggplot(movies, aes(x = runtime, y = rating, col = genre)) + geom_point()

*** =sct

# SCT written with testwhat: https://github.com/datacamp/testwhat/wiki

msg_bad <- "That is not correct!"
msg_success <- "Exactly! There seems to be a very bad action movie in the dataset."
test_mc(correct = 2, feedback_msgs = c(msg_bad, msg_success, msg_bad, msg_bad))

--- type:NormalExercise lang:r xp:100 skills:1 key:e619cd064b

More movies

In the previous exercise, you saw a dataset about movies. In this exercise, we'll have a look at yet another dataset about movies!

A dataset with a selection of movies, movie_selection, is available in the workspace.

*** =instructions

  • Check out the structure of movie_selection.
  • Select movies with a rating of 5 or higher. Assign the result to good_movies.
  • Use plot() to plot good_movies$Run on the x-axis, good_movies$Rating on the y-axis and set col to good_movies$Genre.

*** =hint

  • Use str() for the first instruction.
  • For the second instruction, you should use ...[movie_selection$Rating >= 5, ].
  • For the plot, use plot(x = ..., y = ..., col = ...).

*** =pre_exercise_code

# You can also prepare your dataset in a specific way in the pre exercise code

library(MindOnStats)
data(Movies)
movie_selection <- Movies[Movies$Genre %in% c("action", "animated", "comedy"),c("Genre", "Rating", "Run")]

# Clean up the environment
rm(Movies)

*** =sample_code

# movie_selection is available in your workspace

# Check out the structure of movie_selection


# Select movies that have a rating of 5 or higher: good_movies


# Plot Run (i.e. run time) on the x axis, Rating on the y axis, and set the color using Genre

*** =solution

# movie_selection is available in your workspace

# Check out the structure of movie_selection
str(movie_selection)

# Select movies that have a rating of 5 or higher: good_movies
good_movies <- movie_selection[movie_selection$Rating >= 5, ]

# Plot Run (i.e. run time) on the x axis, Rating on the y axis, and set the color using Genre
plot(good_movies$Run, good_movies$Rating, col = good_movies$Genre)

*** =sct

# SCT written with testwhat: https://github.com/datacamp/testwhat/wiki

test_function("str", args = "object",
              not_called_msg = "You didn't call `str()`!",
              incorrect_msg = "You didn't call `str(object = ...)` with the correct argument, `object`.")

test_object("good_movies")

test_function("plot", args = "x")
test_function("plot", args = "y")
test_function("plot", args = "col")

test_error()

success_msg("Good work!")