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

Barth B. Riley bbriley at chestnut.org
Wed Apr 27 14:38:36 CEST 2011


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.



More information about the R-help mailing list