[R] hash - extract key values

William Dunlap wdunlap at tibco.com
Sun Mar 29 00:57:56 CET 2015


What part of the following does not work as expected?
   > z <- hash(keys=letters[1:5], values=lapply(1:5,seq_len))
   > keys(z)
   [1] "a" "b" "c" "d" "e"
   > z$b
   [1] 1 2


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Mar 28, 2015 at 4:45 PM, Brian Smith <bsmith030465 at gmail.com> wrote:

> Hi William,
>
> That's the point - the 'keys()' doesn't seem to work..
>
>
> On Sat, Mar 28, 2015 at 7:36 PM, William Dunlap <wdunlap at tibco.com> wrote:
>
>> Try using the plural 'keys' instead of 'key' (as help(hash) says):
>>    yourhash <- hash(keys=letters, values=1:26)
>> Then there will be 26 items in the hash table and keys(yourhash)
>> will return the 26 lowercase letters.  Is that what you want?
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>> On Sat, Mar 28, 2015 at 2:56 PM, Brian Smith <bsmith030465 at gmail.com>
>> wrote:
>>
>>> I deleted the 'hash' directory and re-installed (several times!) it, but
>>> it
>>> is still wierd......
>>>
>>>
>>> > sessionInfo()
>>> R version 3.1.2 (2014-10-31)
>>> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>>>
>>> locale:
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> loaded via a namespace (and not attached):
>>> [1] tools_3.1.2
>>> > library(hash)
>>> hash-3.0.1 provided by Decision Patterns
>>>
>>> > myhash <- hash(key=letters,values=1:26)
>>> > myhash
>>> <hash> containing 2 key-value pair(s).
>>>   key : a b c d e f g h i j k l m n o p q r s t u v w x y z
>>>   values :  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
>>> 22 23 24 25 26
>>> > keys(myhash)
>>> [1] "key"    "values"
>>> > myhash$key
>>>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
>>> "r" "s" "t" "u" "v" "w" "x" "y" "z"
>>> > myhash$values
>>>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
>>> 24 25 26
>>> > sessionInfo()
>>> R version 3.1.2 (2014-10-31)
>>> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>>>
>>> locale:
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> other attached packages:
>>> [1] hash_3.0.1
>>>
>>> loaded via a namespace (and not attached):
>>> [1] tools_3.1.2
>>> >
>>>
>>> On Sat, Mar 28, 2015 at 5:02 AM, Uwe Ligges <
>>> ligges at statistik.tu-dortmund.de
>>> > wrote:
>>>
>>> > Try to reinstall hash. Sounds like a broken installation.
>>> >
>>> > Best,
>>> > Uwe Ligges
>>> >
>>> >
>>> >
>>> > On 28.03.2015 07:03, Brian Smith wrote:
>>> >
>>> >> Exactly. Used to work for me, but not anymore. I tried restarting
>>> session,
>>> >> installing the most recent package of 'hash' etc.
>>> >>
>>> >> Here is my sessionInfo():
>>> >>
>>> >>  sessionInfo()
>>> >>>
>>> >> R version 3.1.2 (2014-10-31)
>>> >> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>>> >>
>>> >> locale:
>>> >> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>> >>
>>> >> attached base packages:
>>> >>   [1] grid      parallel  stats4    stats     graphics  grDevices
>>> utils
>>> >> datasets  methods   base
>>> >>
>>> >> other attached packages:
>>> >>   [1] mapdata_2.2-3        maps_2.3-9           org.Hs.eg.db_3.0.0
>>> >> multicore_0.1-7      nlme_3.1-120         Rgraphviz_2.10.0
>>> >>   [7] biomaRt_2.22.0       topGO_2.18.0         SparseM_1.6
>>> >>   GO.db_3.0.0          graph_1.44.1         mouse4302.db_3.0.0
>>> >> [13] org.Mm.eg.db_3.0.0   RSQLite_1.0.0        DBI_0.3.1
>>> >>   AnnotationDbi_1.28.1 GenomeInfoDb_1.2.4   IRanges_2.0.1
>>> >> [19] S4Vectors_0.4.0      Biobase_2.26.0       BiocGenerics_0.12.1
>>> >>   XML_3.98-1.1         gap_1.1-12           som_0.3-5
>>> >> [25] pvclust_1.3-2        foreign_0.8-63       hash_3.0.1
>>> >>
>>> >> loaded via a namespace (and not attached):
>>> >> [1] bitops_1.0-6    lattice_0.20-29 RCurl_1.95-4.5  tools_3.1.2
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> On Fri, Mar 27, 2015 at 9:54 PM, Boris Steipe <
>>> boris.steipe at utoronto.ca>
>>> >> wrote:
>>> >>
>>> >>  Works for me :
>>> >>>
>>> >>>  library(hash)
>>> >>>>
>>> >>> hash-2.2.6 provided by Decision Patterns
>>> >>>
>>> >>>  hx <- hash( c('a','b','c'), 1:3 )
>>> >>>> class(hx)
>>> >>>>
>>> >>> [1] "hash"
>>> >>> attr(,"package")
>>> >>> [1] "hash"
>>> >>>
>>> >>>> hx$a
>>> >>>>
>>> >>> [1] 1
>>> >>>
>>> >>>> keys(hx)
>>> >>>>
>>> >>> [1] "a" "b" "c"
>>> >>>
>>> >>>
>>> >>> Maybe restart your session? Clear your workspace? Upgrade?
>>> >>>
>>> >>> B.
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>> On Mar 27, 2015, at 7:39 PM, Brian Smith <bsmith030465 at gmail.com>
>>> wrote:
>>> >>>
>>> >>>  Hi,
>>> >>>>
>>> >>>> I was trying to use hash, but can't seem to get the keys from the
>>> hash.
>>> >>>> According to the hash documentation ('hash' package pdf, the
>>> following
>>> >>>> should work:
>>> >>>>
>>> >>>>  hx <- hash( c('a','b','c'), 1:3 )
>>> >>>>> class(hx)
>>> >>>>>
>>> >>>> [1] "hash"
>>> >>>> attr(,"package")
>>> >>>> [1] "hash"
>>> >>>>
>>> >>>>> hx$a
>>> >>>>>
>>> >>>> [1] 1
>>> >>>>
>>> >>>>> keys(hx)
>>> >>>>>
>>> >>>> Error in (function (classes, fdef, mtable)  :
>>> >>>>   unable to find an inherited method for function ‘keys’ for
>>> signature
>>> >>>> ‘"hash"’
>>> >>>>
>>> >>>> How can I get the keys for my hash?
>>> >>>>
>>> >>>> thanks!
>>> >>>>
>>> >>>>        [[alternative HTML version deleted]]
>>> >>>>
>>> >>>> ______________________________________________
>>> >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> >>>> PLEASE do read the posting guide
>>> >>>>
>>> >>> http://www.R-project.org/posting-guide.html
>>> >>>
>>> >>>> and provide commented, minimal, self-contained, reproducible code.
>>> >>>>
>>> >>>
>>> >>>
>>> >>>
>>> >>         [[alternative HTML version deleted]]
>>> >>
>>> >> ______________________________________________
>>> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>>> >> PLEASE do read the posting guide http://www.R-project.org/
>>> >> posting-guide.html
>>> >> and provide commented, minimal, self-contained, reproducible code.
>>> >>
>>> >>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list