[R] IMPORTANT - To remove the null elements from a vector

Paul Hiemstra p.hiemstra at geo.uu.nl
Tue Mar 9 14:14:25 CET 2010


Barbara.Rogo at uniroma1.it wrote:
> I have a vector that have null elements. How to remove these elements?
> For example:
> x=[10 0 30 40 0 0] I want the vector y=[10 30 40]
> Thanks
> 	[[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.
>   
and, to add to the options already posted:

subset(x, x != 0)

cheers,
Paul

-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul



More information about the R-help mailing list