[R] What is the equivalent of column.prods() from S in R?

William Dunlap wdunlap at tibco.com
Sun Nov 29 06:38:58 CET 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Peng Yu
> Sent: Saturday, November 28, 2009 8:29 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] What is the equivalent of column.prods() from S in R?
> 
> On Mon, Nov 9, 2009 at 8:35 PM, David Winsemius 
> <dwinsemius at comcast.net> wrote:
> >
> > On Nov 9, 2009, at 8:43 PM, Peng Yu wrote:
> >
> >> Chambers' book Statistical Models in S mentioned 
> 'column.prods()'. But
> >> I don't find it in R. I'm wondering if there is an equivalent in R?
> >
> > ??rowProds
> > ??colProds
> >
> > (They are in both fUtilities and timeSeries.)
> 
> Are you sure that colProds() is equivalent to column.prods()? It seems
> that column.prods() should be a very basic function in S, but I have
> to load a package in order to call colProds().
> 
> I don't see how to construct a matrix give terms as mentioned in the
> book. Would you please give me some examples?

S's and S+'s column.prods(x1,x2), where nrow(x1)==nrow(x2),
returns the nrow(x1) row by ncol(x1)*ncol(x2) column matrix
containing the products of all pairs of columns
from x1 and x2, respectively.  The column names are set to
reflect which columns in x1 and x2 the products come from.
E.g., one can use it to compute the interaction colunns
in a model matrix:
  > x1<-cbind(one=c(1,0,0),two=c(0,1,0))
  > x2<-cbind(A=c(11,12,13), B=c(101,105,111))
  > column.prods(x1,x2)
       oneA twoA oneB twoB
  [1,]   11    0  101    0
  [2,]    0   12    0  105
  [3,]    0    0    0    0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 




More information about the R-help mailing list