【发布时间】:2011-04-07 15:07:37
【问题描述】:
我提供此示例数据来解决我的问题。
aid=c(1,2,3,4,5,6,7,8,9,10)
foson=c(0,1,2,0,6,9,0,0,3,0)
fosof=c(0,0,2,3,0,0,0,5,0,0)
data=data.frame(aid,foson,fosof)
现在,我需要创建一个名为 data$hist 的新变量(列),条件如下:
if foson==0 and fosof==0, then hist = 0;
if foson >=1 and fosof==0, then hist = 1;
if foson==0 and fosof>=1, then hist = 2; and
if foson>=1 and fosof>=1, then hist = 3
我尝试使用“ifelse”功能,但未能成功。
我希望问题足够清楚。
感谢大家的帮助,
巴松
【问题讨论】:
标签: r conditional-statements multiple-columns