[R] how to delete the null elements in list

Rui Barradas ruipbarradas at sapo.pt
Fri Jan 25 14:15:37 CET 2013


Hello,

Try the following.

suu <- list(NULL, NULL, 1:2, matrix(1:4, 2))
suu[!sapply(suu, is.null)]


Hope this helps,

Rui Barradas


Em 25-01-2013 12:31, Tammy Ma escreveu:
>
> HI,
>
> I have the list:
>
>
>> suu
> [[1]]
> NULL
>
> [[2]]
> NULL
>
> [[3]]
> item_id  prod
>   1           2
>
> [[4]]
>
> item_id prod
> 1          2
> 2          4
>
>
>
> how to delete all "NULL" elements from suu to get only
>
>> suu
>
> [[3]]
> item_id  prod
>   1           2
>
> [[4]]
>
> item_id prod
> 1          2
> 2          4
>
>
> ??
>
>
> Kind regards,
> Tammy
>
>   		 	   		
> 	[[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