From Kurt.Hornik@ci.tuwien.ac.at  Mon Aug 25 08:10:20 1997
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Mon, 25 Aug 1997 09:10:20 +0200
Subject: R-alpha: tapply() strangeness
Message-ID: <199708250710.JAA14123@aragorn.ci.tuwien.ac.at>

Here's something related to last week's apply() problem:

R> x <- matrix(1:20, nc = 4)
R> x
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20

R> tapply(x, row(x), table)
[1] Numeric,4 Numeric,4 Numeric,4 Numeric,4 Numeric,4

???

In S,

> tapply(x, row(x), table)
$"1":
 1 6 11 16 
 1 1  1  1

$"2":
 2 7 12 17 
 1 1  1  1

$"3":
 3 8 13 18 
 1 1  1  1

$"4":
 4 9 14 19 
 1 1  1  1

$"5":
 5 10 15 20 
 1  1  1  1

which is (apart from labels) the same as

R> lapply(split(x, row(x)), table)
$1
 1  6 11 16 
 1  1  1  1 

$2
 2  7 12 17 
 1  1  1  1 

$3
 3  8 13 18 
 1  1  1  1 

$4
 4  9 14 19 
 1  1  1  1 

$5
 5 10 15 20 
 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: tapply() strangeness
Kurt Hornik