【发布时间】:2016-07-31 20:32:51
【问题描述】:
在下面的例子中,i.want.them.all如何得到从5到14的所有10个数字?
control.me <- 0 # or 1
a.lot.of.elements <- c(5:14)
i.want.them.all <- ifelse(control.me == 1, a.lot.of.elements, a.lot.of.elements - 10)
print(i.want.them.all)
[1] 5
有这样的构造吗? :
a.lot.of.elements <- c(5:14)
i.want.them.now <- magic.construct(control.me == 1, a.lot.of.elements, a.lot.of.elements - 10)
print(i.want.them.now)
[1] 5 6 7 8 9 10 11 12 13 14
如果没有,我怎么能完成我想做的事?
【问题讨论】:
-
如果您的条件导致
length == 1“逻辑”,您可以使用简单的if(test) yes else no。?ifelse声明“测试”决定了输出的大多数属性(包括length) -
你应该阅读
help(ifelse)
标签: r if-statement