use*_*432 3 r
我有一个数据帧"df".我想从条件语句创建两个子集(a&b),比如变量"x",其值大于10.在SAS中,这将是: data a, b; set df; if x>10 then output a; else output b.在R中有办法做到这一点吗?
data a, b; set df; if x>10 then output a; else output b
Jam*_*mes 5
你可以使用split:
split
subs <- split(df,df$x>10) a <- subs[[1]] b <- subs[[2]]
split的第二个参数需要一个因子,因此您可以使用更复杂的语句来提供更多分割.
归档时间:
14 年,10 月 前
查看次数:
1077 次
最近记录: