An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100129/3552503d/attachment.pl>
Vector from Matrix
4 messages · Thiem Alrik, Dennis Murphy, David Winsemius +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100129/f1ea847b/attachment.pl>
On Jan 29, 2010, at 11:25 AM, Thiem Alrik wrote:
Dear Mailing List Members, the problem I've been grappling with f?r quite some time now is the following: I have a 100 rows x 200 columns matrix. data.set <- matrix(rnorm(20000, 100, 200))
I am guessing that you wanted to type: data.set <- matrix(rnorm(20000), 100, 200)
Now I would like to get a vector of length 100 which collects the values from the following procedure: Take the sum of the minima of the two values from each row of columns 1 and 101, and divide it by the sum of column 101.
If so, then this should be step 1: sum( pmin(data.set[,1], data.set[,101]))/sum(data.set[,101])
Do the same for column 2 and 102, 3 and 103 and so on.
Perhaps (runs without error but unverified): sapply(1:100, function(x) sum(pmin(data.set[,x], data.set[,100+x]))/ sum(data.set[,100+x]))
Thanks a lot for your help. Alrik ******************************************* Alrik Thiem Research Assistant WEC E17
David Winsemius, MD Heritage Laboratories West Hartford, CT
Try this also: pmin(data.set[,1:100], data.set[,101:200])/colSums(data.set[,101:200])
On Fri, Jan 29, 2010 at 2:25 PM, Thiem Alrik <thiem at sipo.gess.ethz.ch> wrote:
Dear Mailing List Members, the problem I've been grappling with f?r quite some time now is the following: I have a 100 rows x 200 columns matrix. data.set <- matrix(rnorm(20000, 100, 200)) Now I would like to get a vector of length 100 which collects the values from the following procedure: Take the sum of the minima of the two values from each row of columns 1 and 101, and divide it by the sum of column 101. Do the same for column 2 and 102, 3 and 103 and so on. Thanks a lot for your help. Alrik ******************************************* Alrik Thiem Research Assistant WEC E17 Weinbergstrasse 11 Center for Comparative and International Studies (CIS) and Center for Security Studies (CSS) Swiss Federal Institute of Technology Zurich CH-8092 Zurich Tel.: 0041 44 63 20937 thiem at sipo.gess.ethz.ch http://www.cis.ethz.ch/ http://www.css.ethz.ch/ ******************************************* ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at 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.
Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O