[R] How to dynamically replace the text behind dollar sign: '$'

谢一鸣 13636622737 at 163.com
Wed Feb 6 07:48:29 CET 2013


Thanks David, your solution perfectly solve my problem. But Do you know what exactly the mechanism of "Computing on the language" in pdf file: "R language definition", Can that "THING" do the same job?

Thank you very much!
Xie YM

2013-02-06 14:22:57,"David Winsemius" <dwinsemius at comcast.net> 写道:
>The "$" construction is only a syntactic shortcut for "[["argument"]].  
>What you are looking for is described in the ?"[[" page. You should be  
>constructing a formal that is assigned a syntactically legal column  
>name ...  NOT "ANYTHING I WANT". Perhaps:
>
>function(dfrm , colname = "V1") {
>       return( dfrm[[ colname ]] )
># the argument will get evaluated as "V1" unless an alternate colname  
>argument is supplied
>       }
>
>( You can't get "$" to evaluate a character column name.)
>
>--
>David Winsemius, MD
>Alameda, CA, USA
>



More information about the R-help mailing list