[R] request: How can we ignore a component of list having no element
Adaikalavan Ramasamy
a.ramasamy at imperial.ac.uk
Wed Oct 15 16:47:49 CEST 2008
Try
x[ !sapply(x, is.null) ]
hadley wickham wrote:
> An alternative approach would be to store 0 x 0 matrices instead of
> NULLs. This way every object in your list is a consistent type.
>
> Hadley
>
> On Wed, Oct 15, 2008 at 5:23 AM, Muhammad Azam <mazam72 at yahoo.com> wrote:
>> Dear friends
>> There is a list of arrays comprising different no of rows and columns even sometimes NULL, such as [[2]] given below. How can we ignore [[2]] or others like this in the complete list. Any help in this regard is needed. Thanks
>>
>> [[1]]
>> [,1] [,2]
>> [1,] 3 1
>> [2,] 3 1
>> [3,] 3 1
>>
>> [[2]]
>> NULL
>>
>> [[3]]
>> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
>> [1,] 3 1 0 0 0 0 0
>> [2,] 3 1 0 0 0 0 0
>> [3,] 3 1 0 0 0 0 0
>> [4,] 3 1 3 1 3 2 1
>> [5,] 3 1 3 1 3 2 1
>> [6,] 3 1 3 1 3 2 0
>>
>> [[4]]
>> [,1] [,2] [,3] [,4]
>> [1,] 3 0 0 0
>> [2,] 3 1 3 3
>> [3,] 3 1 3 3
>> [4,] 3 1 3 0
>>
>> OR
>> x1=c(1,2,3); x2=c(1,2,3,4,6); x3=c(); x=list(x1,x2,x3)
>>
>> M.Azam
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>
>
>
>
More information about the R-help
mailing list