Reputation: 5287
I have number of results to pass back to a calling procedure I'd like to pass back a named list where each result is numbered.
# the following works
# result is a valid result
results = list( "1" = result)
When I do the following I end up with results$resultCounter instead of results$'1'
resultCounter = 1
results = list( resultCounter = result)
How do you pass in the contents of a variable to be the name of an element within a list?
Upvotes: 1
Views: 50
Reputation: 887531
One option would be to use setNames
results <- setNames(result, resultCounter)
result <- list(1:5, 6:10)
resultCounter <- 1:2
Upvotes: 2