how do you retrieve the names of the objects of a list in a loop. I want to do something like this:
lst = list(a = c(1,2), b = 1)
for(x in lst){
#print the name of the object x in the list
# print the multiplication of the values
}
Desired results:
"a"
2 4
"b"
2
In Python one can use dictionary and with the below code get the desired results:
lst = {"a":[1,2,3], "b":1}
for key , value in lst.items():
print(key)
print(value * 2)
but since in R we have no dictionary data structure, I am trying to achieve this using lists but I don't know how to return the objects names. Any help would be appreciated.