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