From kevinushey at gmail.com  Mon Apr 27 15:30:11 2015
From: kevinushey at gmail.com (Kevin Ushey)
Date: Mon, 27 Apr 2015 06:30:11 -0700
Subject: [Rd] Inconsistency when naming a vector
In-Reply-To: <CAPtbhHzDnoP1VPxeGiSrojY3Sav4Y8qtq_5rqHyizef=+tmHPg@mail.gmail.com>
References: <CABdHhvGLwS8RbZ9QXtHjr=NoSHyEqMKcUDh7598jNMFUKKit2A@mail.gmail.com>
	<CAPtbhHzDnoP1VPxeGiSrojY3Sav4Y8qtq_5rqHyizef=+tmHPg@mail.gmail.com>
Message-ID: <CAJXgQP0rTF3aTNhMYhUOGJNva73_0wrT3Z-rP6s+mjG0uUSL9A@mail.gmail.com>

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.g. in subsetting operations) but
there may be some subtle cases where they're not.


On Mon, Apr 27, 2015 at 6:08 AM, Suzen, Mehmet <msuzen at gmail.com> wrote:
>
> 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
>
> where as in the second case, R uses default value "", from `names`
> documentation "..The name "" is special: it is used to indicate that
> there is no name associated with an element.". Since you defined the
> first one, it internally assigns "" to non-defined names to match the
> length of the vector.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Inconsistency when naming a vector
Kevin Ushey