Re: [R] NA values in indexing

2010-03-26 Thread Barry Rowlingson
On Fri, Mar 26, 2010 at 4:15 PM, Matthew Dowle wrote: > The type of 'NA' is logical. So x[NA] behaves more like x[TRUE] i.e. silent > recycling. > >> class(NA) > [1] "logical" >> x=101:108 >> x[NA] > [1] NA NA NA NA NA NA NA NA >> x[c(TRUE,NA)] > [1] 101  NA 103  NA 105  NA 107  NA > >> x[as.integ

Re: [R] NA values in indexing

2010-03-26 Thread Barry Rowlingson
On Fri, Mar 26, 2010 at 4:15 PM, Bert Gunter wrote: > Is this, from the man page, relevant? > > "An empty index selects all values: this is most often used to replace all > the entries but keep the attributes. " No, I think that means doing "x[]", and only in replacement: > x=101:105 > attr(x,"

Re: [R] NA values in indexing

2010-03-26 Thread Bert Gunter
-boun...@r-project.org] On Behalf Of Barry Rowlingson Sent: Friday, March 26, 2010 5:10 AM To: r-help@r-project.org Subject: [R] NA values in indexing If you index a vector with a vector that has NA in it, you get NA back: > x=101:107 > x[c(NA,4,NA)] [1] NA 104 NA > x[c(4,NA)] [1] 104 NA

Re: [R] NA values in indexing

2010-03-26 Thread Gabor Grothendieck
Try > x <- 101:107 > x[c(NA_integer_, NA_integer_)] [1] NA NA On Fri, Mar 26, 2010 at 8:09 AM, Barry Rowlingson wrote: > If you index a vector with a vector that has NA in it, you get NA back: > >  > x=101:107 >  > x[c(NA,4,NA)] >  [1]  NA 104  NA >  > x[c(4,NA)] >  [1] 104  NA > > All well and

Re: [R] NA values in indexing

2010-03-26 Thread Matthew Dowle
The type of 'NA' is logical. So x[NA] behaves more like x[TRUE] i.e. silent recycling. > class(NA) [1] "logical" > x=101:108 > x[NA] [1] NA NA NA NA NA NA NA NA > x[c(TRUE,NA)] [1] 101 NA 103 NA 105 NA 107 NA > x[as.integer(NA)] [1] NA HTH Matthew "Barry Rowlingson" wrote in message news

[R] NA values in indexing

2010-03-26 Thread Barry Rowlingson
If you index a vector with a vector that has NA in it, you get NA back: > x=101:107 > x[c(NA,4,NA)] [1] NA 104 NA > x[c(4,NA)] [1] 104 NA All well and good. ?"[" says, under NAs in indexing: When extracting, a numerical, logical or character ‘NA’ index picks an unknown element