Skip to content
Prev 323680 / 398503 Next

To List or Not To List

You can use an environment with much of the same syntax that you use a list;
in particular assign() and get() are not needed because you can use env[["name"]]
instead of assign("name", envir=env) and get("name", envir=env).  You are using
quantmod so I assume you are using getSymbols() to retrieve the data.  Use its
env= argument to put the results into an environment.  Then you have all your stock
data in one place and objects(env) will list the names of things in it.  Loop over every
object in the environment with eapply().  You don't waste any time 'collecting all
the data in a list' because you create in an environment in the first place.
(It has to go in some environment, so put it in a convenient one - it will help you keep
organized.)
[1] "TIBX" "IBM"  "M"
[1] "IBM"  "M"    "TIBX"
TIBX.Close
2007-01-03       9.66
2007-01-04       9.68
2007-01-05       9.68
2007-01-08       9.89
2007-01-09       9.69
$TIBX
           TIBX.Open TIBX.High TIBX.Low TIBX.Close TIBX.Volume TIBX.Adjusted
2013-05-08     20.62     21.17    20.48      21.16     6371000         21.16
2013-05-09     21.10     21.15    20.57      20.65     2322300         20.65
2013-05-10     20.70     21.02    20.68      20.89     1746500         20.89
2013-05-13     20.89     20.95    20.56      20.61     1114500         20.61
2013-05-14     20.60     20.97    20.55      20.82     1176700         20.82
2013-05-15     20.61     21.09    20.61      21.07     2775500         21.07

$IBM
           IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
2013-05-08   202.94   204.85  202.51    204.82    3601700       204.82
2013-05-09   204.69   205.00  202.72    203.24    3542300       203.24
2013-05-10   203.37   204.53  202.82    204.47    3279200       204.47
2013-05-13   204.18   204.47  202.22    202.47    3648400       202.47
2013-05-14   202.09   203.67  202.08    203.21    3699700       203.21
2013-05-15   202.25   203.68  202.04    203.32    4028100       203.32

$M
           M.Open M.High M.Low M.Close M.Volume M.Adjusted
2013-05-08  46.54  47.12 46.26   46.64  3440600      46.64
2013-05-09  46.59  46.81 46.26   46.45  2676800      46.45
2013-05-10  46.62  47.23 46.58   47.23  2999300      47.23
2013-05-13  47.02  47.12 46.54   46.88  2687700      46.88
2013-05-14  47.00  47.67 46.92   47.39  4491000      47.39
2013-05-15  48.25  48.93 47.30   48.57  9460700      48.57

 
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com