[R-pkg-devel] Return Value of By Function

Dario Strbenac dstr7320 at uni.sydney.edu.au
Tue Sep 15 07:00:05 CEST 2015


Good day,

I am curious why the by function result has dimensions attached, even when it returns a list.

result <- by(warpbreaks[, 1],   warpbreaks[, -1], summary)
str(result)

List of 6
...
- attr(*, "dim")= int [1:2] 2 3
 - attr(*, "dimnames")=List of 2
  ..$ wool   : chr [1:2] "A" "B"
  ..$ tension: chr [1:3] "L" "M" "H"

Also, why does looking at the top of the list remove the names ?

> head(result, 3)
[[1]]
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  25.00   26.00   51.00   44.56   54.00   70.00 

[[2]]
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  14.00   20.00   29.00   28.22   31.00   44.00 

[[3]]
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
     12      18      21      24      30      36

Compared to :

> result
wool: A
tension: L
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  25.00   26.00   51.00   44.56   54.00   70.00 
...

I can't tell which list entry is for which combination of factors, after it is accessed. It would be great if it was easier to get the factor levels used for each list element, perhaps as a data.frame.

--------------------------------------
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia



More information about the R-package-devel mailing list