我正在尝试使用其他列中的值在数据框中添加字段,具体取决于另一列中的条件。
df <- data.frame(condition= c("startBin>7 & startBin<=12 & endBin>25 & endBin<=30","(startBin<=7 | startBin>12) & (endBin<=25 | endBin>30)","(startBin>7 & startBin<=12) & (endBin<=25 | endBin>30)","(startBin<=7 | startBin>12) & endBin>25 & endBin<=30"),
startBin = c(1,1,1,1), endBin = c(26,26,26,26), exprTemp=c("One","Two","Three","Four"))
我想创建一个列&#34;检查&#34;如果条件为&#34;条件&#34;则值为1列满意。因此,我希望更新的数据框为:
df <- data.frame(condition= c("startBin>7 & startBin<=12 & endBin>25 & endBin<=30","(startBin<=7 | startBin>12) & (endBin<=25 | endBin>30)","(startBin>7 & startBin<=12) & (endBin<=25 | endBin>30)","(startBin<=7 | startBin>12) & endBin>25 & endBin<=30"),
startBin = c(1,1,1,1), endBin = c(26,26,26,26), exprTemp=c("One","Two","Three","Four"), check=c(0,0,0,1))
请注意,对于条件为真的最后一条记录,check的值为1。
我尝试了以下内容:
df$check <- eval(parse(text=paste0("ifelse(",df$condition,",1, '')",sep="")),df)
但它为所有行返回check = 1,因为eval仅评估最后一个条件。
答案 0 :(得分:1)
请尝试以下代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1){
setResult(resultCode,data);
}
finish();
}