Skip to content
Prev 167895 / 398503 Next

looping over a string

Ah, I missed that.  You can get the value from the string by using paste to create the name of the variable (as you already did), then use the 'get' function to get its value (the other direction of assign).  But I would still suggest trying to use lists, then you can just use mylist[[ i ]] or mylist[[ names[i] ]] to grab the value or mylist[[ i ]] <- something  to assign.  Or even better, newlist <- lapply( oldlist, function ) and avoid the explicit loop altogether (then if you want to use the individual variables by name, just use with or within).

Hope this helps,