[R] how to eliminate an element of a list
David Winsemius
dwinsemius at comcast.net
Sat Aug 14 05:30:17 CEST 2010
On Aug 13, 2010, at 4:06 PM, fishkbob wrote:
>
>> list<-seq(2,10,2)
>> list
> [1] 2 4 6 8 10
>> list[-which(2==list)]
> [1] 4 6 8 10
>
> using the which() will let you remove things from a list that have a
> specified value... I usually use the
>
> blah<- blah[-which(TRUE==is.na(blah)) ]
>
> which will remove all NA values in your list
Although which() is useful when used with "[" because it avoids the NA
indexing problem, it is entirely superfluous here.
blah<- blah[-is.na(blah) ] # will be more efficient
>
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list