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, --Clayton -- Clayton Springer, Ph. D. Sandia National Laboratories csprin at ca.sandia.gov Biosystems Research Department (925) 294-2143 P.O. Box 969, MS 9951 fax: (925) 294-3020 Livermore, CA, 94551-0969 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 8 Nov 2001, Clayton Springer wrote:> 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). >You can index a matrix, dataframe, or list by names eg using part of the summary.lm output data(swiss) cc<-summary(lm(Fertility ~ . , data = swiss))$coef cc["Agriculture",] cc[,"Estimate"] cc["Education","Pr(>|t|)"] -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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] > xa 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._