Re: [R] how to divide each element of a matrix by a specific value per column

2011-01-27 Thread Henrique Dallazuanna
Try this: sweep(y, 2, x, "/") On Thu, Jan 27, 2011 at 1:18 PM, adam_pgsql wrote: > > Hi, > > I'd like to divide each element of a matrix by a specific value per column. > These specific values are stored in a list. For example: > > > x <- c(1,2,3,4,5) > > y <- matrix(c(1:30), nrow = 6) > > Now

Re: [R] how to divide each element of a matrix by a specific value per column

2011-01-27 Thread Marc Schwartz
On Jan 27, 2011, at 9:18 AM, adam_pgsql wrote: > > Hi, > > I'd like to divide each element of a matrix by a specific value per column. > These specific values are stored in a list. For example: > >> x <- c(1,2,3,4,5) >> y <- matrix(c(1:30), nrow = 6) > > Now I want to divide each element in

Re: [R] how to divide each element of a matrix by a specific value per column

2011-01-27 Thread Dennis Murphy
Here's one way: y/outer(rep(1, nrow(y)), x) [,1] [,2] [,3] [,4] [,5] [1,]1 3.5 4.33 4.75 5.0 [2,]2 4.0 4.67 5.00 5.2 [3,]3 4.5 5.00 5.25 5.4 [4,]4 5.0 5.33 5.50 5.6 [5,]5 5.5 5.67 5.75 5.8 [6,]6 6.0 6.00 6.00 6.0 Run the outer c

[R] how to divide each element of a matrix by a specific value per column

2011-01-27 Thread adam_pgsql
Hi, I'd like to divide each element of a matrix by a specific value per column. These specific values are stored in a list. For example: > x <- c(1,2,3,4,5) > y <- matrix(c(1:30), nrow = 6) Now I want to divide each element in y[,1] by x[1], y[,2] by x[2] etc. I have tried this > my_function