在R中编码伪变量和条件语句

时间:2018-07-25 02:49:28

标签: r if-statement conditional

我熟悉以这种方式编码虚拟变量以用于回归分析(例如,来自面板数据中区域的编码)

    dum1<-ifelse(var=="condition",1,0)

我想知道的是为什么当我尝试用这种方式进行编码

    if(variable=="condition"){dum1<-1} else {dum1<-0}

我明白了:

Warning message: In if (variable == "condition") { : the condition has length > 1 and only the first element will be used

有人可以帮我解释一下吗?谢谢

0 个答案:

没有答案