Hi my data looks like X=(3,5,6,7) B= 1 2 3 4 and C=( 1 2 3 4) 2 3 4 5 4 5 6 7 8 9 1 2 I want my results to be XB + C. Please help me use apply in this function ----- Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Multiplication-usijg-apply-tp4405903p4405903.html Sent from the R help mailing list archive at Nabble.com.
On 21-02-2012, at 04:41, arunkumar1111 wrote:> Hi > > my data > > looks like > > X=(3,5,6,7) B= 1 2 3 4 and C=( 1 2 3 4) > 2 3 4 5 > 4 5 6 7 > 8 9 1 2 > > > I want my results to be > > XB + C. > > Please help me use apply in this function >Why apply? Maybe this is what you want:> X<- c(3,5,6,7) > B<- matrix(c(1, 2, 3, 4,+ 2, 3, 4, 5, + 4, 5, 6, 7, + 8, 9, 1, 2), nrow=4,byrow=TRUE)> C <- c(1, 2, 3, 4) > > matrix(X, nrow=1) %*% B %*% matrix(C,ncol=1)[,1] [1,] 909 Berend