【问题标题】:How to use macro variable in R如何在 R 中使用宏变量
【发布时间】:2019-01-26 19:17:03
【问题描述】:

这是一个使用宏变量的 SAS 代码,但我试图在 R 中执行此操作。是否可以在 R 中使用宏?

%macro LOOCV;*Macro Name is LOOCV;
*Take one row out at a time, and there are 295 rows;
%do i = 1 %to 59;
data epilepsy_long_cv;
   set epilepsy_long; *Find ith row and set weekly rate to missing, so the model building doesnt use ith observation;
   if ID = &i then Weeklyrate=.; 
run;

proc Reg Data=epilepsy_long_cv noprint;*Use noprint to suppress output;
   model WeeklyRate = Age Time Trt;
   output out=work.pred  p=predict;
run;
quit;

【问题讨论】:

  • 你不能在 r 中使用宏,你必须学会​​以不同的方式思考 i R,这可能会非常令人困惑。一些在 SAS 中容易的任务在 r 中变得困难,但另一种方式也成立。大多数情况下,我认为宏的替代品是编写函数。从 SAS 更改为 r 可能会非常混乱。
  • 如果您可以描述输入的样子(最好通过使用dput(YOUR_DATA_HERE 共享示例)、宏需要做什么以及输出应该是什么,这将有所帮助。我确信这在 R 中是可能的,但如果没有更多信息,将很难提供帮助。

标签: r


【解决方案1】:

在 R 中,您编写用户 functions 而不是 SAS macros。 IE。如果您希望在 R 中复制 proc reg (SAS) 以进行线性建模,则必须找到与此过程等效的 R 并对其进行等效参数化。我假设在 R 中您正在寻找 lm 和 predict 方法。

【讨论】:

    猜你喜欢
    • 2021-10-17
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 2013-06-16
    相关资源
    最近更新 更多