[R] Data.Frame Multiplication
Christian Schulz
c.schulz at metafacts.de
Thu Apr 18 16:25:11 CEST 2002
..many thanks !
Achim Zeileis wrote:
>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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Mit freundlichen Grüßen
Christian Schulz
MetaFacts GmbH
Fon: +49 (0)30 69 51 71 - 0
Fax: +49 (0)30 69 51 71 - 33
mailto:c.schulz at metafacts.de
http://www.metafacts.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20020418/75d86981/attachment.html
More information about the R-help
mailing list