[R] hashing using named lists
Tony Plate
tplate at blackmesacapital.com
Thu Nov 18 19:15:16 CET 2004
Use match() for exact matching,
i.e.,
> test[[match("name", names(test))]]
Yes, it is more cumbersome. This partial matching is considered by some to
be a design fault, but changing it would break too many programs that
depend upon it.
I don't understand your question about all.equal.list() -- it does seem to
require exact matches on names, e.g.:
> all.equal(list(a=1:3), list(aa=1:3))
[1] "Names: 1 string mismatches"
> all.equal(list(aa=1:3), list(a=1:3))
[1] "Names: 1 string mismatches"
>
(the above run in R 2.0.0)
-- Tony Plate
(BTW, in R this operation is generally called "indexing" or "subscripting"
or "extraction", but not "hashing". "Hashing" is a specific technique for
managing and looking up indices, which is why some other programming
languages refer to list-like objects that are indexed by character strings
as "hashes". I don't think hashing is used for list names in R, but
someone please correct me if I'm wrong! )
At Thursday 09:29 AM 11/18/2004, ulas karaoz wrote:
>hi all,
>I am trying to use named list to hash a bunch of vector by name, for instance:
>test = list()
>test$name = c(1,2,3)
>
>the problem is that when i try to get the values back by using the name,
>the matching isn't done in an exact way, so
>test$na is not NULL.
>
>is there a way around this?
>Why by default all.equal.list doesnt require an exact match?
>How can I do hashing in R?
>
>thanks.
>ulas.
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list