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)
> 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
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
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