Re: [R] Is this sapply behaviour normal?

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Thu, 26 Jun 2008 15:25:16 +0200

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 26 Jun 2008 - 13:38:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Jun 2008 - 16:31:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive