Skip to content
Prev 159599 / 398500 Next

calculating mean for samples

assuming that A1 is the data provided in the first post... it would be
helpful if you used dput() to copy into an email, so that we could
just copy the code and data right into a R session and be off and
running.  I hope this helps.

#I used dput() on the object A1
A1 <- (structure(list(s1 = c(0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L),
    s2 = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), s3 = c(0L,
    1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), s4 = c(1L, 0L, 0L, 0L,
    1L, 0L, 0L, 0L, 0L, 1L)), .Names = c("s1", "s2", "s3", "s4"
), class = "data.frame", row.names = c(NA, -10L)))

f <- do.call(rbind , rep(A1[sample(nrow(A1), 5),], 5))
d <- apply(f, MARGIN=1, FUN=mean)
mean(d[names(d)==s1])
mean(d[names(d)==s2])
mean(d[names(d)==s3])
mean(d[names(d)==s4])
On Mon, Oct 20, 2008 at 2:44 PM, al ex <loyola9988 at yahoo.com> wrote: