Creating a named list (2)

Being a huge movie fan (remember your job at LucasFilms), you decide to start storing information on good movies with the help of lists.

Start by creating a list for the movie "The Shining". We have already created the variables mov, act and rev in your R workspace. Feel free to check them out in the console.

Instruction

Complete the code on the right to create shining_list; it contains three elements:

Do not forget to name the list components accordingly (names are moviename, actors and reviews).

mov <- "The Shining" act <- c("Jack Nicholson","Shelley Duvall","Danny Lloyd","Scatman Crothers","Barry Nelson") sources <- c("IMDb1","IMDb2","IMDb3") comments <- c("Best Horror Film I Have Ever Seen","A truly brilliant and scary film from Stanley Kubrick","A masterpiece of psychological horror") scores <- c(4.5,4,5) rev <- data.frame(scores, sources, comments) rm(scores, sources, comments) # The variables mov, act and rev are available # Finish the code to build shining_list shining_list <- list(moviename = mov) # The variables mov, act and rev are available # Finish the code to build shining_list shining_list <- list(moviename = mov, actors = act, reviews = rev) msg = "Do not remove or change the definition of the pre-set variables!" lapply(c("mov", "rev", "act"), test_object, undefined_msg = msg, incorrect_msg = msg) test_object("shining_list", incorrect_msg = "It looks like `shining_list` does not contain the correct elements: the first element should be `mov`, the second element `act`, and the third `rev`.") test_object("shining_list", eq_condition = "equal", incorrect_msg = "It looks like `shining_list` does not contain the correct naming for the components: name the first element `moviename`, the second element `actors`, and the third element `reviews`."); success_msg("Wonderful! You now know how to construct and name lists. As in the previous chapters, let's look at how to select elements for lists. Head over to the next exercise")

shining_list <- list(moviename = mov) is only part of the solution; it's your job to also add act and rev to the list, with the appropriate names.

Previous: 6-4 | Creating a named list

Next: 6-6 | Selecting elements from a list

Back to Main