Since b is only one column, just make it a vector. 

> a <- matrix(c(1,1,1,1,2,2,2,2),4,2)
> b <- c(1,2,3,4)

then

> result <- a/b
> result
          [,1]      [,2]
[1,] 1.0000000 2.0000000
[2,] 0.5000000 1.0000000
[3,] 0.3333333 0.6666667
[4,] 0.2500000 0.5000000

should be what you want. 

It is also a bad idea to name the resulting matrix "c" since c(...) is a
primitive function.

Christian



On Fri, 2010-04-16 at 09:30 -0800, Kathie wrote:
> Dear R users,
> 
> I am looking for more efficient way to compute the followings
> 
> --------------------------------------------------------------------------
> 
> a <- matrix(c(1,1,1,1,2,2,2,2),4,2)
> b <- matrix(c(1,2,3,4),4,1)
> 
> Eventually, I want to get this matrix, `c`.
> 
> c <- matrix(c(1/1,1/2,1/3,1/4,2/1,2/2,2/3,2/4),4,2)
> 
> --------------------------------------------------------------------------
> 
> In fact, #column of `a` is so big..
> 
> Is there a more efficient way to compute this instead of using "apply" or
> something? or "apply" is only way..?
> 
> Any suggestion will be greatly appreciated.
> 
> Regards,
> 
> Kathryn Lord 

-- 
Christian Raschke
Department of Economics and
ISDS Research Lab (HSRG)
Louisiana State University
Patrick Taylor Hall, Rm 2128
Baton Rouge, LA 70803
cras...@lsu.edu

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to