To iterate over a list by key, value pair, do this:
for (name in names(myList)) { print(name)<br /> print(myList[[name]])<br /> }
Note the double [[]] so you get just the value, not the pair.
To iterate over a list by key, value pair, do this:
for (name in names(myList)) { print(name)<br /> print(myList[[name]])<br /> }
Note the double [[]] so you get just the value, not the pair.
This entry was posted on Tuesday, March 16th, 2010 at 10:52 pm and is filed under r, stats. You can follow any comments to this entry through the RSS 2.0 feed. You can leave a comment, or trackback from your own site.
© 2013.
Thanks for that snippet!
I was able to write a script that allows me to list the levels associated with each of the named variables.
Ian
Very helpful. Better than the usual “LOOPS ARE EVIL!!111111″ instructions. Thanks!