[R] boxplot() from list

Marc Schwartz MSchwartz at MedAnalytics.com
Sun Sep 12 18:31:59 CEST 2004

On Sun, 2004-09-12 at 10:10, Laura Quinn wrote:
> I have a list containing 48 objects (each with 30 rows and 4 columns, all
> numeric), and wish to produce 4 boxplot series (with 48 plots in each) ,
> one for each column of each object.
> Basically I want a boxplot from boxplot(mylist[[]][,i])
> for i in 1:4. It seems that I can create a boxplot of length 48 from the
> entire list, but I don't seem able to subscript to return 4 boxplots from
> the list - I have also tried to create 4 new lists (one for each column of
> each object) by using variations on the following, but none seems to work:
> newlist<-oldlist[,1]
> newlist<-oldlist[[]][,1]
> newlist<-oldlist[[]][,$colone]
> can anyone please offer some insight??
> Thanks in advance,

For each individual boxplot, you could do something like:

boxplot(data.frame(sapply(mylist, function(x) x[, 1])))

adjusting the index (1) for each of the four columns in your list

You can then adjust the additional arguments to boxplot() as you

See ?sapply for more information on accessing list member elements and
returning a vector or matrix.


Marc Schwartz

More information about the R-help mailing list