Off topic:how to replace r code inside function body
2
0
Entering edit mode
6.5 years ago
ycding • 0

I want to write a user defined function that I can replace part of R codes.

first, I ran the following code.

middle.pred.young <-PAMfunction(training=middle, met.status=middle$met, 
test=young, ....)
correlation.middle <-corfunction(middle.pred.young)
(more R code with different functions to process the file 
                 "middle.pred.young)

then, I replaced the word "middle" a few times to run the following codes;

old.pred.young <-PAMfunction(training=old, met.status=old$met, test=young, 
....)
correlation.old <-corfunction(old.pred.young)

then more similar code I need to run;

   all_age.pred.young <-PAMfunction(training=all_age, met.status=all_age$met, 
   test=young, ....)
   correlation.allage <-corfunction(all_age.pred.young)

so, I only need to replace one word. I would like to copy SAS macro idea in R.

   %macro predict;

   &age..pred.young <-PAMfunction(training=&age, met.status=&age.$met, 
                                    test=young, ....);
   correlation.&age <-corfunction(&age..pred.young);
        .....;
   %mend;

    %predict(age="old")
    %predict(age="middle")
    %predict(age="all_age")

Can you do me a great favor to write R function to do the repetitive job?

Thank you,

Ding

R • 1.1k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1501 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6