[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


Hello,

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

<R>
testarr<-matrix(1:30, nrow=5)
rownames(testarr)<-letters[1:5]
colnames(testarr)<-LETTERS[1:6]
apply(testarr,1,function(x) {x11(); barplot(x)}) #the funcion used is
actually more compex, but it doesn't matter
</R>

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

main="what_should_I_paste_here?"

Asking for
<R>
str(apply(testarr,1,function(x) {x11(); barplot(x)}))
</R>
gives

<Routput>
 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" ...
</Routput>

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...

Thanks,
Jan

-------------------------------------------------
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