[R] Is this sapply behaviour normal?
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu Jun 26 15:25:16 CEST 2008
Kenn Konstabel wrote:
> On Thu, Jun 26, 2008 at 12:14 AM, Wacek Kusnierczyk <
> Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>
>
>>> sapply(dats,function(x){sapply(x,min)})
>>>
>> you can achieve the same with
>>
>> sapply(dats, sapply, min)
>>
>>
>>
> Did you actually try it?
>
>
>> dats <- data.frame(1:10,2:11)
>> sapply(dats,sapply,min)
>>
> X1.10 X2.11
> [1,] 1 2
> [2,] 2 3
> [3,] 3 4
> [4,] 4 5
> [5,] 5 6
> [6,] 6 7
> [7,] 7 8
> [8,] 8 9
> [9,] 9 10
> [10,] 10 11
>
> Sapply doesn't (or can't?) pass arguments to another sapply -- maybe the
> trick can be done without an anonymous function but not the way you
> suggested.
>
>
did you actually read the original mail? there dats was a *list* of
data frames.
try this:
d = data.frame(a=1:10. b=11:20)
l = list(a=d, b=d)
sapply(l, sapply, min)
sapply(l. function(d) sapply(d, min))
did you actually read the docs for sapply? there ... stands for
optional arguments to FUN.
try this:
?sapply
vQ
More information about the R-help
mailing list