[R] Working with Data Frames

Robert Sherry rsherry8 at comcast.net
Wed Nov 4 01:26:34 CET 2015


I have created what I believe to be a data frame. It is called 
env1$SPY.  The r statement head( env1$SPY ) produces the following output:

            SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
1995-01-03  45.7031  45.8437 45.6875   45.7812     324300 31.55312
1995-01-04  45.9843  46.0000 45.7500   46.0000     351800 31.70392
1995-01-05  46.0312  46.1093 45.9531   46.0000      89800 31.70392
1995-01-06  46.0937  46.2500 45.9062   46.0468     448400 31.73617
1995-01-09  46.0312  46.0937 46.0000   46.0937      36800 31.76850
1995-01-10  46.2031  46.3906 46.1406   46.1406     229800 31.80082

The above data from was created by the following commands:
     library( quantmod )
     env1 <- new.env()
     getSymbols("SPY", src = 'yahoo', from = '1995-01-01', env = env1, 
auto.assign = T)

Now, what I want to do is to loo through the data look for when the 
month changes. What is the proper way of writing a for loop in
R and access the date field?

Bob



More information about the R-help mailing list