[R] first value...

Carl Witthoft carl at witthoft.com
Wed Jun 24 03:15:22 CEST 2009


The various which(is.na) sort of things are fine, but this problem is 
just screaming to be solved with rle().

Just do rle(is.na(inc))$lengths[1]+1






 > On Tue, Jun 23, 2009 at 11:00 AM, Alfredo Alessandrini
<alfreale74 at gmail.com
 > > wrote:
 >
 > > Hi,
 > >
 > > I've a vector like this:
 > >
 > > > inc
 > >  [1]        NA        NA        NA        NA        NA        NA  NA
 > >  [8]        NA        NA        NA        NA        NA        NA  NA
 > >  [15]        NA        NA        NA        NA        NA        NA   NA
 > >  [22]        NA        NA        NA        NA        NA        NA   NA
 > >  [29]        NA        NA        NA        NA        NA        NA   NA
 > >  [36]        NA        NA        NA        NA        NA        NA   NA
 > >  [43]        NA        NA        NA        NA        NA        NA   NA
 > >  [50]        NA        NA        NA        NA        NA        NA   NA
 > >  [57]        NA        NA        NA        NA        NA        NA   NA
 > >  [64]        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
 > >  [85]  8.711888  7.201234 13.029250 14.430755  8.662832  8.810785
14.421302
 > >  [92]  7.614985  7.548091  9.843389 14.977402 20.875255  7.787543
2.005056
 > >  [99]  4.016916  3.601773  4.140390  7.241999 13.280794 18.038902
18.762169
 > >
 > > I must obtain the position of first value of the vector...
 > >
 > > In this case is 82.
 > >
 > > > inc[82]
 > > [1] 13.09550




More information about the R-help mailing list