[R] hash table access, vector access &c

Sam Steingold sds at gnu.org
Tue Jul 5 20:10:53 CEST 2011


> * David Winsemius <qjvafrzvhf at pbzpnfg.arg> [2011-07-05 13:21:57 -0400]:
> On Jul 5, 2011, at 12:53 PM, Sam Steingold wrote:
>> I am confused by the way the indexing works.
> Actually I suspect you may be confused by how factors work. See below.

probably both :-(

being a lisper, I thought about factors as lisp symbols (and thus
thought that they would be accepted everywhere strings are).

> Have you considered:
>
>  ysmd.table[ as.character( ysmd$X.stock[[100]])  ]
>
> It appears that ysmd$X.stock[[100]] is a factor, and if so, you probably
> want the character value that its numeric representation points to.

indeed:

> as.character(ysmd$X.stock[[100]])
[1] "FLO"

however,

> ysmd.table[as.character(ysmd$X.stock[[100]])]
<hash> containing 0 key-value pair(s).
  NA : NULL

so, as.character is not the answer.

> ysmd.table[["FLO"]]
    X.stock market.cap X52.week.low X52.week.high X3.month.average.daily.volume
100     FLO  2.984e+09      15.3133         22.37                       1021580
    X50.day.moving.average.price
100                      21.3769

> This is, of course, guesswork because you have not disclosed what
> package hash` comes from, so I do not have the benefit of looking at
> its help page.

I just did this:

library(hash);
hash-2.0.1 provided by Open Data.


thanks a lot for your help!

-- 
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://jihadwatch.org http://iris.org.il http://honestreporting.com
http://openvotingconsortium.org http://thereligionofpeace.com
Lisp: Serious empowerment.



More information about the R-help mailing list