[R] How to get relevant dimnames from apply() ?

Jan_Svatos@eurotel.cz Jan_Svatos at eurotel.cz
Thu Jul 11 10:18:50 CEST 2002


in order to vectorize task (of plotting barplots), I use, as probably all
R-folks, function apply()
instead of for() loop.

testarr<-matrix(1:30, nrow=5)
apply(testarr,1,function(x) {x11(); barplot(x)}) #the funcion used is
actually more compex, but it doesn't matter

Now, how I can propagate the rownames of testarr into the main label of
plot via


Asking for
str(apply(testarr,1,function(x) {x11(); barplot(x)}))

 num [1:6, 1:5] 0.7 1.9 3.1 4.3 5.5 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "a" "b" "c" "d" ...

but how it is possible to put dimnames of _this_ (i.e., the rownames of
testarr) into "main" label of a plot?
With for() loop, the task is trivial, but with apply?
The problem I need to solve is OK (in terms of performance) with for()
loops, but apply is more elegant
and , of course, much more in R-style...


designed for _monospaced_ font
/- Jan Svatos,  PhD         Sokolovska 855/225 -/
/- Data Analyst             Prague 9           -/
/- Eurotel Praha            190 00             -/
/- jan_svatos at eurotel.cz    Czechia            -/

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list