[R] hash table access, vector access &c
Sam Steingold
sds at gnu.org
Tue Jul 5 21:30:02 CEST 2011
> * David Winsemius <qjvafrzvhf at pbzpnfg.arg> [2011-07-05 14:39:09 -0400]:
>
> So you are here demonstrating that you should be using "[["
yes, thanks!
now, how do I extend a frame with new columns based on a hash table?
specifically, I have a frame:
> str(etr.rt)
'data.frame': 75986 obs. of 15 variables:
$ aaaaaa : POSIXlt, format: ...
$ bbbbb : POSIXlt, format: ...
$ cccccccc : num ...
$ symbol : Factor w/ 4521 levels "A","AA","AACC",..: 985 985 2322 3677 4486 4486 1607 3677 4486 1279 ...
$ dddd : int 500 500 ...
$ eeeeeeee : num 16.61 5.74 ...
and a hash table:
> str(ysmd.table)
Formal class 'hash' [package "hash"] with 1 slots
..@ .xData:<environment: 0x7f0e0e8>
> summary(ysmd.table)
Length Class Mode
7757 hash S4
> ysmd.table[[as.character(etr.rt$symbol[[100]])]]
X.stock market.cap X52.week.low X52.week.high
3122 DFS 1.4606e+10 12.11 26.95
X3.month.average.daily.volume X50.day.moving.average.price
3122 6153430 24.0242
I want to modify etr.rt (or create a new frame etr.rt.md) which would
have all the columns of etr.rt plus 5 additional columns
market.cap
X52.week.low
X52.week.high
X3.month.average.daily.volume
X50.day.moving.average.price
which for the row number i in etr.rt come from
ysmd.table[[as.character(etr.rt$symbol[[i]])]]
(obviously,
etr.rt$symbol[[i]] == ysmd.table[[as.character(etr.rt$symbol[[i]])]]$X.stock
)
thanks!
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://thereligionofpeace.com http://dhimmi.com http://ffii.org
http://pmw.org.il http://mideasttruth.com http://openvotingconsortium.org
The early bird may get the worm, but the second mouse gets the cheese.
More information about the R-help
mailing list