[R] force apply() to return a list
Robin Hankin
r.hankin at noc.soton.ac.uk
Mon Nov 21 09:40:19 CET 2005
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
More information about the R-help
mailing list