[R] determination of number of entries in list elements

Martin Maechler maechler at stat.math.ethz.ch
Sat May 20 13:21:05 CEST 2006


The answer is: 

    sapply(mlist, length)

to the question :

>>>>> "Benjamin" == Benjamin Otto <b.otto at uke.uni-hamburg.de>
>>>>>     on Fri, 19 May 2006 12:09:43 +0200 writes:

    Benjamin> Hi, is there some elegant way to determine the
    Benjamin> number of components stored in each list element?

    Benjamin> Example:

    Benjamin> The list: ---------
    >> list

    Benjamin> $Elem1 [1] A B C

    Benjamin> $Elem1 [1] D

    Benjamin> $Elem1 [1] E F

    Benjamin> Then normal command "length(list)" would return
    Benjamin> 3. But I would like some command return the array
    Benjamin> of the single element lengths like

    Benjamin> [1] 3 1 2

    Benjamin> so I can afterwards get my list subset with only
    Benjamin> entries which have a certain amount of components
    Benjamin> bigger or lower than a certain threshold.

    Benjamin> regards

    Benjamin> Benjamin

    Benjamin> ______________________________________________
    Benjamin> R-help at stat.math.ethz.ch mailing list
    Benjamin> https://stat.ethz.ch/mailman/listinfo/r-help
    Benjamin> PLEASE do read the posting guide!
    Benjamin> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list