Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Introduction to lists
Accessing list elements
Unnamed lists
Working with lists
22. Modifying an existing element of a list
Summary

## Instruction

Great! Let's move on and learn how to change, add, and delete list members.

After speaking with Emma on the phone, you discovered that you have the wrong info about her age in your list. It says she's 35, but she mentioned that she's actually 31. You'd like to update this information.

We learned that we can access the member named age by using the following notation: candidate["age"]. When you run this code, R prints 35 to the console.

To change the value of this member, we simply use the assignment operator to feed the member a new value, like this:

candidate[["age"]] <- 31

With this notation, we're able to modify the value stored in the age member of the candidate list. Now, that member contains the value 31.

You may use the dollar notation as well, like so:

candidate\$age <- 31

The result will be exactly the same: age will now contain the value 31.

For unnamed lists, you can use the [[]] operator with the appropriate index. Here's an example:

candidate[[2]] <- 31

## Exercise

Most of our applicants have fewer than 10 years of experience, so we've decided to reduce the number of years of experience required from 10 to 7. Change the value stored in the years_of_experience member of the job_role list.