On 8/26/06, Patrick Connolly <[EMAIL PROTECTED]> wrote:
> On Sat, 26-Aug-2006 at 09:57AM +0100, Patrick Burns wrote:
>
> |>  > sub.m <- lapply(m, function(x)x[x>2])
> |>  > sub.m
> |> [[1]]
> |> [1] 3 4
> |>
> |> [[2]]
> |> [1] 4 5
> |>
> |> [[3]]
> |> [1] 4
> |>
> |>  > sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))]
> |> [[1]]
> |> [1] 3 4
> |>
> |> [[2]]
> |> [1] 4 5
> |>
> |>  > sub4.m <- lapply(m, function(x)x[x>4])
> |>  > sub4.m[unlist(lapply(sub4.m, function(x) length(x) > 0))]
> |> [[1]]
> |> [1] 5
>
> Or slightly shorter in this case:
>
> sub.m[sapply(sub.m, function(x) length(x) == 2)]
>

or even shorter:

sub.m[sapply(sub.m, length) == 2]

______________________________________________
R-help@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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to