I have two variables, key
and value
, and I want to add them as a key/value pair to a list:
key = \"width\"
value = 32
mylist = lis
List elements in R can be named. So in your case just do
> mylist = list()
> mylist$width = value
When R encounters this code
> l$somename=something
where l is a list. It appends to a list an element something, and names it with name somename. It is then can be accessed by using
> l[["somename"]]
or
> l$somename
The name can be changed with command names:
> names(l)[names(l)=="somename"] <- "othername"
Or if you now the position of the element in the list by:
> names(l)[1] <- "someothername"