How do I use a macro variable in R? (Similar to %LET in SAS)

后端 未结 3 1263
猫巷女王i
猫巷女王i 2020-12-09 13:53

How do I assign a macro variable in R?

In SAS, I would use the following code

%LET DEPVAR = sales_ind

PROC REG DATA=mydata;
MODEL &DEPVAR = VAR1         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-09 14:12

    None of them works. The macro variable is invoked with & in SAS but no similar & being used in R although you can use new=as.name("f3") or new=quote(f3) to refer to f3 as shown below.

    > test<-data.frame(f1=c(1,2), f2=c("a","b")); test
    #   f1 f2
    #1  1  a
    #2  2  b
    
    > new=as.name("f3"); new; 
    #f3
    > new=quote(f3); new; 
    #f3
    
    > # you still get new rather than f3 as expected
    > new<-test$f1; 
    > new
    #[1] 1 2
    

提交回复
热议问题