[R] Problem indexing into array
Ted Harding
Ted.Harding at nessie.mcc.ac.uk
Fri Jul 18 16:36:16 CEST 2003
Hi Folks,
Can anyone give me the tip I've been groping for with the
following question:?
mu: kx2x2x2 array of reals corresponding to means of k RVs
at the combinations of values (1,2)x(1,2)x(1,2)
of dichotomous variables F1,F2,F3
mu prints out as k rows (one for each Xi) of 8 numbers
M: N x (3+k) matrix of cases. The first 3 cols are values
of (F1,F2,F3) as above (and the remainder are values
of (X1,...,Xk) but this doesn't really matter).
AIM: For each row of M, find from mu the set of k means
mu_1,...,mu_k corresponding to the values of F1, F2, F3
in that row. E.g. if M[1,1:3] -> 2,1,1 I want mu[,2,1,1]
BUT: Not to have to do it by mu[,M[1,1],M[1,2],M[1,3]] but more
like mu[,M[1,1:3]] -- except that this kind of try does not
work, leading to error: "incorrect number of dimensions".
So:
HOW To construct an object F from M[1,1:3] such that
mu[,F] gives mu[,2,1,1]
NEXT QUESTION: If the above can be done, I'd really like to be
able to "vectorise" it so as to get ti all at once from all the
rows of M, rather than having to bind the results of a loop over
the rows of M, i.e. achieve what you'd naively expect
mu[,M[,1:3]]
to do (except that even mu[,M[1,1:3]] won't work).
With thanks,
Ted.
More information about the R-help
mailing list