Hi Jim, that's exactly what I'm looking for. Thank you so much. I think, I should look for some further documentation on list handling. Many thanks also to "[EMAIL PROTECTED]" ;) for spending time in finding a solution...
Have a nice day! Antje jim holtman schrieb: > This should do it: > >> v1 <- NA >> v2 <- rnorm(6) >> v3 <- rnorm(6) >> v4 <- rnorm(6) >> v5 <- rnorm(6) >> v6 <- rnorm(6) >> v7 <- rnorm(6) >> v8 <- rnorm(6) >> v8 <- NA >> >> list <- list(v1,v2,v3,v4,v5,v6,v7,v8) >> categ <- c(NA,"cat1","cat1","cat1","cat2","cat2","cat2",NA) >> >> # create partitioned list >> list.cat <- split(list, categ) >> # combine each partition into a matrix >> list.mat <- lapply(list.cat, function(x) do.call('rbind', x)) >> # now take the means of each column >> lapply(list.mat, colMeans) > $cat1 > [1] -0.5699080 0.3855693 1.1051809 0.2379324 0.6684713 0.3240003 > > $cat2 > [1] 0.38160462 -0.10559496 -0.40963090 -0.09507354 0.95021406 -0.31491450 > > > > On 7/30/07, Antje <[EMAIL PROTECTED]> wrote: >> okay, I played a bit around and now I have some kind of testcase for you: >> >> v1 <- NA >> v2 <- rnorm(6) >> v3 <- rnorm(6) >> v4 <- rnorm(6) >> v5 <- rnorm(6) >> v6 <- rnorm(6) >> v7 <- rnorm(6) >> v8 <- rnorm(6) >> v8 <- NA >> >> list <- list(v1,v2,v3,v4,v5,v6,v7,v8) >> categ <- c(NA,"cat1","cat1","cat1","cat2","cat2","cat2",NA) >> >> > list >> [[1]] >> [1] NA >> >> [[2]] >> [1] -0.6442149 -0.2047012 -1.1986041 -0.2097442 -0.7343465 -1.3888750 >> >> [[3]] >> [1] 0.02354036 -1.36186952 -0.42197792 1.50445971 -1.76763996 0.53722404 >> >> [[4]] >> [1] -1.40362589 0.13045724 -0.84651458 1.57005071 0.06961015 0.25269771 >> >> [[5]] >> [1] -1.1829260 2.1411553 -0.1327081 -0.1053442 -0.8179396 -1.2342698 >> >> [[6]] >> [1] 1.17099178 0.49248118 -0.18690065 1.50050976 -0.65552410 -0.01243247 >> >> [[7]] >> [1] -0.046778203 -0.233788840 0.443908897 -1.649740180 0.003991354 >> -0.228020092 >> >> [[8]] >> [1] NA >> >> now, I need the means (and sd) of element 1 of list[2],list[3],list[4] >> (because they belong to "cat1") and >> >> = mean(-0.6442149, 0.02354036, -1.40362589) >> >> the same for element 2 up to element 6 (--> I would the get a vector >> containing the means for "cat1") >> the same for the vectors belonging to "cat2". >> >> does anybody now understand what I mean? >> >> Antje >> >> ______________________________________________ >> 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. >> > > ______________________________________________ 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.