[R] Data.Frame Multiplication

Achim Zeileis zeileis at ci.tuwien.ac.at
Thu Apr 18 13:14:00 CEST 2002


Christian Schulz wrote:
> 
> Have got  any  R-proffessional  a starting point for me
> how i can write me a function which multiply every column with
> every other column in the data.frame - indenpendent from the dim's .

You could start from a function that multiplies a chosen column `col' of
a data.frame `df' with the following columns

  multiply <- function(df, col) df[,col] * df[,-(1:col), drop = FALSE]

and then apply that to your data.frame `mydata' like

  sapply(1:(ncol(mydata) - 1), function(x) multiply(mydata, x))

For the latter part, there might be a better way to do that depending on
how you want to format the output...
Z 

> Thanks in advance
> regards,Christian
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list