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 . 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The code below takes a matrix x and converts it to a matrix whose columns are the pairwise columns of x. If your data comes in a data frame,df, you can always convert it to a matrix like this: x <- as.matrix(df) In the code below, zz is a matrix whose i,j-th element contains the product of column i and column j. Extract the upper triangular portion of this matrix and reshape that into a matrix. (You can convert that to a data frame if you prefer.) zz <- apply(outer(t(x),x),c(1,4),function(x)list(diag(x))) matrix(unlist(zz[upper.tri(zz)]),nrow=nrow(x)) You might want to test this out a bit since the construction is a bit tricky and I have not extensively tested it. On 18 Apr 2002 at 13:03, 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 . > > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._