[R] Unexpected behavior when giving a value to a new variable based on the value of another variable

John McKown john.archie.mckown at gmail.com
Fri Aug 29 14:46:35 CEST 2014


On Fri, Aug 29, 2014 at 3:53 AM, Angel Rodriguez
<angel.rodriguez at matiainstituto.net> wrote:
>
> Dear subscribers,
>
> I've found that if there is a variable in the dataframe with a name very similar to a new variable, R does not give the correct values to this latter variable based on the values of a third value:
>
>
<snip>
>
> Any clue for this behavior?
>
<snip>
>
> Thank you very much.
>
> Angel Rodriguez-Laso
> Research project manager
> Matia Instituto Gerontologico

That is unusual, but appears to be documented in a section from

?`[`

<quote>
Character indices

Character indices can in some circumstances be partially matched (see
pmatch) to the names or dimnames of the object being subsetted (but
never for subassignment). Unlike S (Becker et al p. 358)), R never
uses partial matching when extracting by [, and partial matching is
not by default used by [[ (see argument exact).

Thus the default behaviour is to use partial matching only when
extracting from recursive objects (except environments) by $. Even in
that case, warnings can be switched on by
options(warnPartialMatchDollar = TRUE).

Neither empty ("") nor NA indices match any names, not even empty nor
missing names. If any object has no names or appropriate dimnames,
they are taken as all "" and so match nothing.
</quote>

Note the commend about "partial matching" in the middle paragraph in
the quote above.

-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! <><
John McKown



More information about the R-help mailing list