Re: [Rd] Inconsistency when naming a vector

2015-04-28 Thread Hadley Wickham
On Mon, Apr 27, 2015 at 8:33 AM, peter dalgaard wrote: > >> On 27 Apr 2015, at 13:48 , Hadley Wickham wrote: >> >> Sometimes the absence of a name is maked by an NA: >> >> x <- 1:2 >> names(x)[[1]] <- "a" >> names(x) >> # [1] "a" NA >> >> Whereas other times its >> >> y <- c(a = 1, 2) >> names(y)

Re: [Rd] Inconsistency when naming a vector

2015-04-27 Thread peter dalgaard
> On 27 Apr 2015, at 13:48 , Hadley Wickham wrote: > > Sometimes the absence of a name is maked by an NA: > > x <- 1:2 > names(x)[[1]] <- "a" > names(x) > # [1] "a" NA > > Whereas other times its > > y <- c(a = 1, 2) > names(y) > # [1] "a" "" > > Is this deliberate? The help for names() is a

Re: [Rd] Inconsistency when naming a vector

2015-04-27 Thread Kevin Ushey
In `?names`: If ‘value’ is shorter than ‘x’, it is extended by character ‘NA’s to the length of ‘x’. So it is as documented. That said, it's somewhat surprising that both NA and "" serve as a placeholder for a 'missing name'; I believe they're treated identically by R under the hood (e

Re: [Rd] Inconsistency when naming a vector

2015-04-27 Thread Suzen, Mehmet
There is no inconsistency. Documentation of `names` says "...value should be a character vector of up to the same length as x..." In the first definition your character vector is not the same length as length of x, so you enforce NA by not defining value[2] x <- 1:2 value<-c("a") value[2] [1] NA