I am trying to use the for loop variables for an assingment in R. Let's say I have a list of 3 strings:
fruits = list('apple', 'pear', 'grape')
I wish to use these names to assign in a for loop e.g.
values = list()
for (name in fruits){
values <- c(values, name = 5)
}
I would want a new list that looks like this:
values
apple = 5
pear = 5
grape = 5
However what I receieve is this:
values
name = 5
name = 5
name = 5
Is this possible in R or can this not be done?
Thanks