Dear Dan, you could just use the following:
V <- cbind(V, 1:n) W <- P[V] I hope this helps. Best, Dimitris ---- Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Daniel Bebber" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, May 12, 2004 2:09 PM Subject: [R] Extracting data from matrices > Dear R list > > I have an m * n matrix P and a vector V of length n containing indices for > rows in P. > For each of the m columns I want to extract the value in the row specified > by V, and put these values into a new vector W of length n. > At present I am doing this with a for. loop, but I imagine there is a faster > way that doesn't involve loops. > If anyone knows the way I would be most grateful. > > Below is the code I am using at present- > > for (i in 1:n){ > W[i]<-P[V[i],i]} > > Many thanks, > Dan Bebber > ____________________________ > Department of Plant Sciences > University of Oxford > South Parks Road > Oxford OX1 3RB > UK > Tel. 01865 275060 > Fax. 01865 275074 > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
