Using R, how to reference variable variables (or variables variable) a la PHP [revisited] -


in previous using r, how reference variable variables (or variables variable) la php[post]

i asked question in r analagous php $$ function:

using r stats, want access variable variable scenario similar php double-dollar-sign technique: http://php.net/manual/en/language.variables.variable.php

specifically, looking function in r equivalent $$ in php.

the get( response works strings (characters).

lapply way loop on lists

or can loop on , values ...

for(name in names(vars))             {             val = vars[[name]]; 

i still haven't had $$ function in r answered, although lapply solved needed in moment.

`$$` <- function 

that allows variable type evaluated. still question.


updates


> mlist = list('four'="score", 'seven'="years"); > str = 'mlist$four' > mlist $four [1] "score"  $seven [1] "years"  > str [1] "mlist$four" > get(str) error in get(str) : object 'mlist$four' not found > mlist$four [1] "score" 

or how attributes object such mobj@index


updates #2

so let's put specific context on need. hacking texreg package build custom latex output of 24 models of regression research paper. using plm fixed effects, , default output of texreg uses dcolumns center, don't (i prefer r@{}l, wanted write own template. purpose me, code this, me write extensible code can use again , again. can rebuild 24 tables across 4 pages in seconds, if data change, or if want tweak function, have nice answer. power of abstraction.

as hacked this, wanted more number of observations, number of groups, can user defined index. in case "country" (wait it, hence, need variable variables).

if lookup of structure, want right there: model$model@index$country nice call $$('model$model@index$country'); can build string using paste. nope, workaround.

getindexcount = function(model,key="country")     {     mya = attr(summary(model)$model,"index");     for(i in 1:length(colnames(mya)))         {         if(colnames(mya)[i] == key) {idx = i; break;}         }     if(!is.na(idx))         {         length(unique(mya[,idx]));         } else {              false;             }     } 


updates #3

using r, on command line, can type in string , gets evaluated. why can't internal function directly accessed, , element captured gets printed screen?

there no equivalent function in r. get() works types, not strings.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -