The following is identical in R and S, but still strange ...
R> apply(matrix(1:20, nc = 4), 1, table)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 1 1 1 1 1
[3,] 1 1 1 1 1
[4,] 1 1 1 1 1
R> apply(matrix(rep(1, 20), nc = 4), 1, table)
[1] 4 4 4 4 4
R> apply(matrix(c(1:4, 1, 6 : 8), nc = 4), 1, table)
[[1]]
1 3 7
2 1 1
[[2]]
2 4 6 8
1 1 1 1
-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
R-alpha: apply()
3 messages · Kurt Hornik, Thomas Lumley, Peter Dalgaard
On Fri, 22 Aug 1997, Kurt Hornik wrote:
The following is identical in R and S, but still strange ...
R> apply(matrix(1:20, nc = 4), 1, table)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 1 1 1 1 1
[3,] 1 1 1 1 1
[4,] 1 1 1 1 1
R> apply(matrix(rep(1, 20), nc = 4), 1, table)
[1] 4 4 4 4 4
Yes it is. This is the sort of thing I meant when I complained about drop=F being the default. The third example should be documented in the man page, which only describes what happens "If each call to FUN returns a vector of length n" In fact the Blue Book help pages and the current S-PLUS help also ignore this possibility. Thomas Lumley ------------------------------------------------------+------ Biostatistics : "Never attribute to malice what : Uni of Washington : can be adequately explained by : Box 357232 : incompetence" - Hanlon's Razor : Seattle WA 98195-7232 : : ------------------------------------------------------------ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- r-devel 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-devel-request@stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Thomas Lumley <thomas@biostat.washington.edu> writes:
On Fri, 22 Aug 1997, Kurt Hornik wrote:
The following is identical in R and S, but still strange ...
R> apply(matrix(1:20, nc = 4), 1, table)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 1 1 1 1 1
[3,] 1 1 1 1 1
[4,] 1 1 1 1 1
R> apply(matrix(rep(1, 20), nc = 4), 1, table)
[1] 4 4 4 4 4
Yes it is. This is the sort of thing I meant when I complained about drop=F being the default. The third example should be documented in the man page, which only describes what happens "If each call to FUN returns a vector of length n" In fact the Blue Book help pages and the current S-PLUS help also ignore this possibility.
The weirdest thing is actually the first case, where tables of the same length *but different dimnames* are getting pasted together into a matrix with no dimnames...
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- r-devel 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-devel-request@stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-