How to add Key Value Pair to List in R ?
A key-value pair can be explained as a set of two linked data items where a key uniquely identifies a value or a set of values in the data. Since a list can hold multiple data-types data, we can have a key-value pair stored in the list
We can assign variables to each key and value. Store each key-value pair after building the list using square brackets.
Another way of doing this without using any additional variables is to specify the key and the value in the list() function while creating the list.
Method 3: Using setNames()
Another approach we can take to add a key-value pair in the list is to setNames() function and inside it, we use as.list(). Basically what we will have here is a syntax like given below, which will create a list and assign all the keys with their respective values.