[R] programming question
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Nov 8 22:40:46 CET 2001
Clayton Springer <csprin at brandybuck.ca.sandia.gov> writes:
> Dear r-help,
>
> I am trying to build a new function (to process rpart objects) that will
> output matrix that has a row for each node and a column for
> each feature. With each entry in the table is a numerical property
> at that node for that feature (e.g. surrogate split agreement, improvement).
>
> My current trouble is that the only clue to the identity of the feature is
> stored as the *name* of the feature. Whereas a table is indexed by *number*.
>
> I have a list of sorted names, but I am having trouble translating a name
> into a number. If this where perl the answer would be a hash.
>
> Or can I directly index a table with an alphanumeric string. (ie. a hash).
>
> Any help would be greatly appreciated,
You can easily index with names:
> x<-1:3
> names(x)<-letters[1:3]
> x
a b c
1 2 3
> x["b"]
b
2
It's not a hash in the perl sense, though. Each lookup does a linear
search. The match() function could also be used.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list