From Kurt.Hornik@ci.tuwien.ac.at  Mon Aug 25 08:07:48 1997
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Mon, 25 Aug 1997 09:07:48 +0200
Subject: R-alpha: apply()
In-Reply-To: <3.0.1.16.19970822182043.51bf2ef2@droopy.iarc.fr>
References: <3.0.1.16.19970822182043.51bf2ef2@droopy.iarc.fr>
Message-ID: <199708250707.JAA14115@aragorn.ci.tuwien.ac.at>

>>>>> Martyn Plummer writes:

> At 12:42 22/08/97, kurt.hornik@ci.tuwien.ac.at 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
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

> It is strange, but logical.  The problem is that it's an undocumented
> feature. If the help page said something like "If the calls to FUN
> return vectors of different lengths then apply returns a list of
> length dim(x)[MARGIN]" then it would be less surprising. Or would you
> prefer that apply returns an error message if it can't coerce the
> result to an array?

No, some explanation would be fine.  But from the examples, I don't
think that we always get a list of a certain length ...

-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()
Kurt Hornik