Hello, I've the following list n:> n[[1]] [1] "NEW" "OLD" "PRG" [[2]] [1] "04h" "24h" [[3]] [1] "000mM" "010mM" "025mM" "050mM" "100mM" where n <- dimnames(some.multidim.array) I'm trying to define a generic function that generates meaningful names from this list, e.g. NEW.04h.000mM would be the first name, then NEW.04h.010mM, ... . Overall this would generate 30 names (3*2*5). Here, this would be 3 cascaded loops, but the dimensions of the array should be flexible. What would suggest? I'm happy for your comments, +regards, Arne
Dear Arne, you could use something like: n <- list(c("NEW", "OLD", "PRG"), c("04h", "24h"), c("000mM", "010mM", "025mM", "050mM", "100mM")) dnames <- apply(expand.grid(n), 1, function(x) paste(x, collapse="")) dnames I hope this helps. Best, Dimitris ---- Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: <Arne.Muller at aventis.com> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, April 27, 2004 11:26 AM Subject: [R] paste dimnames problem> Hello, > > I've the following list n: > > n > [[1]] > [1] "NEW" "OLD" "PRG" > > [[2]] > [1] "04h" "24h" > > [[3]] > [1] "000mM" "010mM" "025mM" "050mM" "100mM" > > where > > n <- dimnames(some.multidim.array) > > I'm trying to define a generic function that generates meaningfulnames from this list, e.g. NEW.04h.000mM would be the first name, then NEW.04h.010mM, ... . Overall this would generate 30 names (3*2*5). Here, this would be 3 cascaded loops, but the dimensions of the array should be flexible.> > What would suggest? > > I'm happy for your comments, > +regards, > > Arne > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html
Try: <<*>>n<-list(c("new","old","prg"), c("04h","24h", "48h"), c("000mM","010mM","025mM", "050mM", "100mM")) unlist(lapply(1:3,function(x) paste(n[[1]][x],n[[2]][x],n[[3]][x],sep="."))) @ output-start Tue Apr 27 12:03:57 2004 [1] "new.04h.000mM" "old.24h.010mM" "prg.48h.025mM" output-end Peter Wolf Arne.Muller at aventis.com wrote:>Hello, > >I've the following list n: > > >>n >> >> >[[1]] >[1] "NEW" "OLD" "PRG" > >[[2]] >[1] "04h" "24h" > >[[3]] >[1] "000mM" "010mM" "025mM" "050mM" "100mM" > >where > >n <- dimnames(some.multidim.array) > >I'm trying to define a generic function that generates meaningful names from this list, e.g. NEW.04h.000mM would be the first name, then NEW.04h.010mM, ... . Overall this would generate 30 names (3*2*5). Here, this would be 3 cascaded loops, but the dimensions of the array should be flexible. > >What would suggest? > > I'm happy for your comments, > +regards, > > Arne > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >