I think what you mean is that you want to find the position of the first
non-NA value in the vector.  is.na returns a boolean vector of the NA
values, so:

xx <- c(NA,NA,NA,2,3,NA,4)
> which(!is.na(xx))[1]
[1] 4

The other proposed solution,

    which(diff(is.na(inc)) < 0)

is incorrect:

> which(diff(is.na(xx))<0)
[1] 3 6

           -s

On Tue, Jun 23, 2009 at 10:00 AM, Alfredo Alessandrini <alfreal...@gmail.com
> wrote:

> Hi,
>
> I've a vector like this:
>
> > inc
>  [1]        NA        NA        NA        NA        NA        NA
>  NA...
> [71]        NA        NA        NA        NA        NA        NA        NA
>  [78]        NA        NA        NA        NA 13.095503 10.140119  7.989186
>
...

> I must obtain the position of first value of the vector...
>
> In this case is 82.
>
> > inc[82]
> [1] 13.09550
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to