[R] force apply() to return a list

Gabor Grothendieck ggrothendieck at gmail.com
Mon Nov 21 14:26:42 CET 2005


Try this:

tapply(a, row(a), f, simplify = FALSE)

tapply(a, row(a), max, simplify = FALSE) # still returns list


On 11/21/05, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
> Hi Dimitris
>
>
> On 21 Nov 2005, at 08:37, Dimitris Rizopoulos wrote:
> > out <- lapply(apply(a2, 1, f), "[[", 1)
>
>
> thanks for this, but it doesn't quite do what I want:
>
>
>  > f <- function(x){1:max(x[1],4)}
>  > lapply(apply(cbind(1:5,5:1), 1, f), "[[", 1)
> [[1]]
> [1] 1
>
> [[2]]
> [1] 1
>
> [[3]]
> [1] 1
>
> [[4]]
> [1] 1
>
> [[5]]
> [1] 1
>
>  >
>
> I want
>
> > [[1]]
> > [1] 1 2 3 4
> >
> > [[2]]
> > [1] 1 2 3 4
> >
> > [[3]]
> > [1] 1 2 3 4
> >
> > [[4]]
> > [1] 1 2 3 4
> >
> > [[5]]
> > [1] 1 2 3 4 5
>
>
>
> best wishes
>
> Robin
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list