Re: [R] boxplot() from list

2004-09-12 Thread Marc Schwartz
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
matrices. 

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

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

HTH,

Marc Schwartz

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] boxplot() from list

2004-09-12 Thread John Fox
Dear Laura,

You don't say what kind of objects are in the list, but suppose that they
are matrices; here's a scaled-down example using 3 list elements:

M1 - matrix(rnorm(30*4), 48, 4)
M2 - matrix(rnorm(30*4), 48, 4)
M3 - matrix(rnorm(30*4), 48, 4)
L - list(M1=M1, M2=M2, M3=M3)

par(mfrow=c(3, 4))
lapply(L, function(x) apply(x, 2, boxplot))

I hope that this helps,
 John 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Laura Quinn
 Sent: Sunday, September 12, 2004 10:10 AM
 To: [EMAIL PROTECTED]
 Subject: [R] boxplot() from list
 
 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,
 
 Laura Quinn
 Institute of Atmospheric Science
 School of Earth and Environment
 University of Leeds
 Leeds
 LS2 9JT

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] boxplot() from list

2004-09-12 Thread Prof Brian Ripley
On Sun, 12 Sep 2004, Marc Schwartz wrote:

 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
 matrices. 
 
 You can then adjust the additional arguments to boxplot() as you
 require.
 
 See ?sapply for more information on accessing list member elements and
 returning a vector or matrix.

I think that is overly complex, as boxplot accepts a list.  I had tested
(but decided not to send)

mylist - vector(list, 48)
for(i in 1:48) mylist[[i]] - matrix(rnorm(30*4), 30) 

for (J in 1:4) boxplot(lapply(mylist, function(x, j) x[, j], j = J))


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] boxplot() from list

2004-09-12 Thread Marc Schwartz
On Sun, 2004-09-12 at 11:42, Prof Brian Ripley wrote:
 On Sun, 12 Sep 2004, Marc Schwartz wrote:
 
  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
  matrices. 
  
  You can then adjust the additional arguments to boxplot() as you
  require.
  
  See ?sapply for more information on accessing list member elements and
  returning a vector or matrix.
 
 I think that is overly complex, as boxplot accepts a list.  I had tested
 (but decided not to send)
 
 mylist - vector(list, 48)
 for(i in 1:48) mylist[[i]] - matrix(rnorm(30*4), 30) 
 
 for (J in 1:4) boxplot(lapply(mylist, function(x, j) x[, j], j = J))


Fair enough. I did not want to presume that the remaining arguments to
boxplot might be the same for each plot. Though one could also put those
into an appropriate structure and still do the loop.

Also, if using the display, one would probably want to set par(ask =
TRUE), lest the four plots flash by in rapid sequence.

Marc

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html