[R] Turning a vector into a matrix based on a matrix of vector indices

From: Barth B. Riley <bbriley_at_chestnut.org>
Date: Wed, 27 Apr 2011 07:38:36 -0500


Hello

I have a matrix (though it could also be a ragged array) called items.used, that has the item numbers of questions administered to a set of respondents. I also have a vector of item parameters called b[]. I am looking for an elegant way to create a matrix b.mat in which each element is the b[x] item parameter, where x is the item number in items.used. When the number of administered items was fixed for all respondents, I would do th following:

ni <- 30
iused.vec <- as.vector(t(items.used[,1:ni])) b.vec <- b[iused.vec]
b.mat <- matrix(b.vec,ncol=ni)

This, however, would not work if the number of items administered to a respondent varies from respondent to respondent.

Any help would be greatly appreciated.

Barth

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance.



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. Received on Wed 27 Apr 2011 - 12:42:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Apr 2011 - 12:50:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive