Dear useRs, I have two different length vectors: one column (1...m) and one row vector (1...n): 20 40 20 60 5 4 2 Now I have to calculate ratios between column vector elements and each row vector elements: 4 5 10 8 10 20 4 5 20 15 12 30 Thank's in advance for any suggestions, Andrej
?outer> v1 <- c(20,40,20,60) > v2 <- c(5,4,2) > outer(v1,v2,'/')[,1] [,2] [,3] [1,] 4 5 10 [2,] 8 10 20 [3,] 4 5 10 [4,] 12 15 30>On 5/26/06, Andrej Kastrin <andrej.kastrin@siol.net> wrote:> > Dear useRs, > > I have two different length vectors: one column (1...m) and one row > vector (1...n): > > 20 > 40 > 20 > 60 > > 5 4 2 > > Now I have to calculate ratios between column vector elements and each > row vector elements: > > 4 5 10 > 8 10 20 > 4 5 20 > 15 12 30 > > Thank's in advance for any suggestions, > > Andrej > > ______________________________________________ > 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 >-- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[alternative HTML version deleted]]
Andrej Kastrin wrote:> Dear useRs, > > I have two different length vectors: one column (1...m) and one row > vector (1...n): > > 20 > 40 > 20 > 60 > > 5 4 2 > > Now I have to calculate ratios between column vector elements and each > row vector elements: > > 4 5 10 > 8 10 20 > 4 5 20 > 15 12 30A <- c(20,40,20,60) B <- c(5,4,2) A %*% t(1/B) [,1] [,2] [,3] [1,] 4 5 10 [2,] 8 10 20 [3,] 4 5 10 [4,] 12 15 30> Thank's in advance for any suggestions, > > Andrej > > ______________________________________________ > R-help at 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-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
> outer(c(20,40,20,60), c(5,4,2), "/")[,1] [,2] [,3] [1,] 4 5 10 [2,] 8 10 20 [3,] 4 5 10 [4,] 12 15 30 cheers D On 26/05/06, Andrej Kastrin <andrej.kastrin at siol.net> wrote:> Dear useRs, > > I have two different length vectors: one column (1...m) and one row > vector (1...n): > > 20 > 40 > 20 > 60 > > 5 4 2 > > Now I have to calculate ratios between column vector elements and each > row vector elements: > > 4 5 10 > 8 10 20 > 4 5 20 > 15 12 30 > > Thank's in advance for any suggestions, > > Andrej > > ______________________________________________ > R-help at 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 >