[R] Find the indices of non-NA elements of a sequence

Berend Hasselman bhh at xs4all.nl
Fri May 17 08:51:54 CEST 2013


On 17-05-2013, at 08:36, jpm miao <miaojpm at gmail.com> wrote:

> Hi,
> 
>  I have a sequence whose 1st, 3rd, 4th, 6th are non-NAs. How could I let R
> return 1,3,4,6, the indices?
> 
>  I know only how to find the non-NA elements. Thanks,
> 
> Miao
> 
>> test<-c(2,NA,6,8,NA,12)
>> test[is.na(test)==FALSE]
> [1]  2  6  8 12


?which

which(!is.na(test))

Berend



More information about the R-help mailing list