[Rd] hash access to data.frame uses prefix? (PR#10474)

ripley at stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Nov 28 10:40:15 CET 2007


Exact matching has preference over partial matching: see ?pmatch.

Your version of R is three versions obsolete: the latest version explains 
this in detail under ?`[.data.frame` and ?`[` (and maybe 2.5.0 does too).

Please do your homework before sending non-bugs to R-bugs.


On Wed, 28 Nov 2007, pkensche at cmbi.ru.nl wrote:

> Full_Name: Philip Kensche
> Version: R version 2.5.0 (2007-04-23)
> OS: Linux
> Submission from: (NULL) (131.174.146.31)
>
>
> I want to access a row of a data.frame() by using the row names as hash keys.

Hmm, you mean you use character vector indices.  No hashing is involved.

> This works fine for most keys.
>
> Now consider the following data.frame().
>
>> x <- data.frame(v=c(V40="a", V411="b"))
>
>> x
>     v
> V40  a
> V411 b
>
> If I query for "V41", which does not exist in the data.frame() the call 
> does not return NA as I would expect but the row "V411".
>
>> x[ "V41", ]
> [1] b
> Levels: a b
>
> If there the prefix is not unique the query does not return a results, i.e.
>
>> x <- data.frame(v=c(V412="a", V411="b"))
>
>> x
>     v
> V412 a
> V411 b
>
>> x[ "V41", ]
> [1] <NA>
> Levels: a b
>
>
> sessionInfo() output:
>> sessionInfo()
> R version 2.5.0 (2007-04-23)
> i686-pc-linux-gnu
>
> locale:
> LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C
>
> attached base packages:
> [1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
> [7] "base"
>
> other attached packages:
> lattice
> "0.15-4"
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list