Skip to content
Prev 62157 / 63424 Next

Should subsetting named vector return named vector including named unmatched elements?

Ji??,

For your first question, the NA names make sense if you think of indexing with a character vector as the same as menu[match(select, names(menu))]. You're not indexing with "beans"; rather, "beans" becomes NA because it's not in the names of menu. (This is how it's documented in ?`[`: "Character vectors will be matched to the names of the object...")

Steve
On Thursday, January 18th, 2024 at 2:51 PM, Ji?? Moravec <jiri.c.moravec at gmail.com> wrote:

            
Message-ID: <ecfPGkO91zz809LB4x8V2jNFBxvHKo4pJA2PBU13HJBOJ6BSvK_nmxgUfd2ZV1476kFwXjTk1MA889H7cMgCmcqcUr98ZOUhdpN2iqN1JFg=@protonmail.com>
In-Reply-To: <9ec19b87-28f2-4de8-81ae-7075b78a6111@gmail.com>