Benjamin Otto
2006-May-19 10:09 UTC
[R] determination of number of entries in list elements
Hi, is there some elegant way to determine the number of components stored in each list element? Example: The list: ---------> list$Elem1 [1] A B C $Elem1 [1] D $Elem1 [1] E F Then normal command "length(list)" would return 3. But I would like some command return the array of the single element lengths like [1] 3 1 2 so I can afterwards get my list subset with only entries which have a certain amount of components bigger or lower than a certain threshold. regards Benjamin
Martin Maechler
2006-May-20 11:21 UTC
[R] determination of number of entries in list elements
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