Re: [R] dataframe (matrix) multiplication

From: Peter Wolf <pwolf_at_wiwi.uni-bielefeld.de>
Date: Fri 14 Oct 2005 - 18:59:21 EST

where is the problem?

input:
A<-c(2,3,2); B<-c(1,2,1); C<-c(4,4,5); D<-c(3,5,4) df<-data.frame(A,B,C,D)
c1<-1:2; c2<-3:4
df[,c1]*df[,c2]

output:

   A B
1 8 3
2 12 10
3 10 4

Peter Wolf

Christoph Scherber wrote:
>Dear R users,
>
>Suppose I have 2 parts of a dataframe, say
>
>ABCD
>2143
>3245
>2154
>
>(the real dataframe is 160 columns with each 120 rows)
>
>and I want to multiply every element in [,A:B] with every element in [,C:D];
>What is the most elegant way to do this?
>
>Ive been thinking of converting [,A:B] to a matrix, and then
>multiplying it with the inverse of [,C:D]; would that be correct?
>
>The result should look like
>
>E;F
>8;3
>12;10
>10;4
>
>Thanks very much for any suggestions
>Christoph
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Oct 14 19:14:04 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:52:19 EST