Adding more movie information to the list

Being proud of your first list, you shared it with the members of your movie hobby club. However, one of the senior members, a guy named M. McDowell, noted that you forgot to add the release year. Given your ambitions to become next year's president of the club, you decide to add this information to the list.

To conveniently add elements to lists you can use the c() function, that you also used to build vectors:

ext_list <- c(my_list , my_val)

This will simply extend the original list, my_list, with the component my_val. This component gets appended to the end of the list. If you want to give the new list item a name, you just add the name as you did before:

ext_list <- c(my_list, my_name = my_val)

Instruction

load(url("http://s3.amazonaws.com/assets.datacamp.com/course/intro_to_r/shining_list.RData")) # shining_list, the list containing movie name, actors and reviews, is pre-loaded in the workspace # We forgot something; add the year to shining_list shining_list_full <- # Have a look at shining_list_full # shining_list, the list containing movie name, actors and reviews, is pre-loaded in the workspace # Use c() to add a year to shining_list shining_list_full <- c(shining_list, year = 1980) # Have a look at shining_list_full str(shining_list_full) msg = "Do not remove or change the definition of `shining_list`, which is pre-loaded in the workspace!" test_object("shining_list", undefined_msg = msg, incorrect_msg = msg) test_object("shining_list_full", eq_condition = "equal", incorrect_msg = paste("Have you correctly extended `shining_list` with an element named `year`,", "whose value is 1980? You can use `c(shining_list, year = 1980)`")) test_function("str", "object", incorrect_msg = "Don't forget to display the structure of `shining_list_full` with `str()`.") success_msg("Great! This was the last exercise on R lists! You now have a solid basis in the R programming language, but there's so much more to learn. Check out all the other DataCamp courses and become a true data science expert!")

Have a look at the example code in the exercise assignment. Maybe this can help you start:

shining_list <- c(shining_list, ...)

You still have to add some code where the three dots are.

Previous: 6-6 | Selecting elements from a list

Back to Main