Ok Josh,

You are absolutely correct. In fact another difference between data frames
and xts objects:

obj[1]  in a dataframe is column 1
obj[1] in a xts object is row 1. I have been bitten by this already a few
times.

So implementation between xts and data frames is indeed different.

For xts objects, as you state, cbind(obj, new.col) creates a new xts object
with a new column.

I did think the same was true with data frames. I know the internal
implementation is different, but from the user's perspective, doesn't
cbind() operate similarly in both cases, via copy operations? There are no
pointers involved are there?

In any case, you guys have given me insight that I did not have and I
appreciate it. I am learning a lot by understanding the construction of
chart_Series and associated objects. I need increased functionality, and it
is not clear to what extent development is currently ongoing.

   Regards,

      Gordon



On Mon, Apr 30, 2012 at 5:19 PM, Joshua Ulrich <josh.m.ulrich@gmail.com>wrote:

> Gordon,
>
> On Mon, Apr 30, 2012 at 3:34 PM, Gordon Erlebacher
> <gordon.erlebach@gmail.com> wrote:
> >
> > In any case, regardless of whether I am expressing myself correctly or
> not,
> > I do understand the differences between xts and data.frame, and I still
> > believe that there must be a way to go from date to row number when
> dealing
> > with xts objects. In the meantime, I'll implement the inefficient
> solution.
> >
> I'm not sure you actually do understand the difference between xts and
> data.frame.  Here's the example you provided:
>
> library("quantmod")
> getSymbols("AAPL")
> AAPL <- cbind(AAPL, index=1:length(AAPL[,1]))
> idx <- function(x, date) { return(x[date]$index) }
> idx(AAPL, '2007-01-10')
>
> And then you commented:
>
> ************
> To accomplish this required a cbind, where I added a column. Doesn't
> this construct a new data.frame with an additional column?
>
> I would have assumed the existence of a function in R to accomplish
> this. After all, a data frame is a list of columns, each column is a
> vector, which is indexed. We are not dealing with hash tables.
> ******************************
>
> You refer to data.frames several times, even though there is no
> data.frame in your example.  You ask, "Doesn't this [cbind] construct
> a new data.frame with an additional column?"  No, it doesn't!  It
> creates a new xts object with an additional column.
>
> Your next comment about data.frames is correct, but completely
> unrelated because xts objects are completely unrelated to data.frames.
>
> Best,
> Josh
>
> >
> > Thanks for all your help and comments.
> >
> Glad you were finally able to get what you needed...
>
> >
> >           Gordon
> >
> >
> >
> >
> > On Mon, Apr 30, 2012 at 4:26 PM, Brian G. Peterson <brian@braverock.com>
> > wrote:
> >>
> >> On Mon, 2012-04-30 at 16:15 -0400, Gordon Erlebacher wrote:
> >> > I would have assumed the existence of a function in R to accomplish
> >> > this.After all, a data frame is a list of columns, each column is a
> >> > vector,which is indexed. We are not dealing with hash tables.
> >>
> >> As Josh already told you, and xts object and a data.frame have *nothing*
> >> to do with each other.
> >>
> >> Your example first creates a data.frame of row numbers, which could be
> >> easily found via which()
> >>
> >> Part of the difficult here is that *usually* if you are referring to row
> >> numbers in an xts object, you're doing it wrong.  For time series data,
> >> refer to the timestamp (the actual index), not to a row number.  You can
> >> reference row numbers in xts, you just usually shouldn't.
> >>
> >>
> >> --
> >> Brian
> >>
> >
> >
> > _______________________________________________
> > R-SIG-Finance@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> > should go.
>

	[[alternative HTML version deleted]]

