From: Benilton Carvalho <bcarvalh_at_jhsph.edu>

Date: Fri 19 Jan 2007 - 23:17:26 GMT

Date: Fri 19 Jan 2007 - 23:17:26 GMT

I have an outcome on an array [N x S x D].

I also have a factor (levels 1,2,3) stored on a matrix N x S.

Ideally the final result would be an array [N x D x 3 x 2].

Thank you very much for any suggestion.

## begin toy example

set.seed(1)

N <- 100 S <- 5 D <- 2

outcome <- array(rnorm(N*S*D), dim=c(N, S, D)) classes <- matrix(sample(c(1:3, NA), N*S, rep=T), ncol=S)

results <- array(NA, dim=c(N, D, 3, 2))

library(MASS)

myHubers <- function(x)

if (length(x)>1) as.numeric(hubers(x)) else c(NA, NA)

for (n in 1:N)

for (d in 1:D){

tmp <- outcome[n,,d] grp <- classes[n,] results[n, d,,] <- t(sapply(split(tmp, factor(grp, levels=1:3)),myHubers))

}

*## end
*

-- Benilton Carvalho PhD Candidate Department of Biostatistics Johns Hopkins University ______________________________________________ R-help@stat.math.ethz.ch 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 Sat Jan 20 10:24:05 2007

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Sat 20 Jan 2007 - 07:30:22 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.
*