Skip to content

Another quantmod question

10 messages · Russ Abbott, David Winsemius, Joshua Wiley +2 more

#
On May 8, 2011, at 3:07 PM, Russ Abbott wrote:

            
I suspect that you are actually using xts objects that you are  
incorrectly calling 'array's. If something is puzzling about the  
behavior of an R object the first thing to do is see what you are  
really dealing with so ... str(object)

If you load the xts package and type ?cbind.xts , you get a help page  
for merge.xts.

(In base R I do not know of a way to assign columns the way you  
propose within a `merge` call.)

Here is the code for cbind.xts:

 > cbind.xts
function (..., all = TRUE, fill = NA, suffixes = NULL)
{
     merge.xts(..., all = all, fill = fill, suffixes = suffixes)
}
<environment: namespace:xts>
David Winsemius, MD
West Hartford, CT
#
Hi Russ,
On Sun, May 8, 2011 at 12:07 PM, Russ Abbott <russ.abbott at gmail.com> wrote:
It would be appreciated in the future if you provided the object via
dput() or some such that is easy to paste in.
Yes.

mat <- matrix(1:10, dimnames = list(NULL, "A"))
cbind(X = 11:20, Y = mat + 1)
cbind(X = 11:20, Y = mat[, "A"] + 1)

In particular note that:

class(mat)
class(mat[, "A"])

It is silly to expect to be able to pass a single name for an entire
matrix, while it makes complete sense that that would work for a
vector.  The problem with naming the column the same thing as the
object containing it, is our limited human minds get ramfeezled (R
does just fine, as you can see).
Nope, but do check the type of object you are working with---there are
often different methods for different objects so I would not assumet
that all things would work the same.

Cheers,

Josh
Please post using plain text.

  
    
#
Russ,
On May 8, 2011 6:29 PM, "Russ Abbott" <russ.abbott at gmail.com> wrote:
Naming columns is not the explicit intent of cbind.  The explicit
intent is to combine objects by columns.  Please don't overstate the
case.

While the examples for the generic show naming columns, neither
?cbind.zoo or ?cbind.xts have such examples.  That's a hint.
If that's not what one wants, one can always write their own
programming language.

Seriously, it seems like you want to rant more than understand what's
going on.  You have the R and xts help pages and the source code.  The
"Note" section of help(cbind) tells you that the method dispatch is
different.  It even tells you what R source file to look at to see how
dispatching is done.  Compare the relevant source files from
base::cbind and xts::cbind.xts, look at the "R Language Definition"
manual to see how method dispatch is normally done.

But you've been writing quite sophisticated code for a fairly long
time, so I'm not telling you anything you don't know... you just don't
think you should have to do the legwork.
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
#
On Sun, May 8, 2011 at 1:17 PM, Russ Abbott <russ.abbott at gmail.com> wrote:
It does.  Thank you.  It sounds like you want to keep the xts class,
so this may not be useful to you, but if you are willing to drop it at
the point you are cbind()ing things together:

cbind(changed.close = as.matrix(close + 1)[, "close"], zero = 0, close)

should do the trick.

Cheers,

Josh