[问题] 关于switch选择

楼主: laputaca (离歌笑)   2015-11-16 22:55:51
[问题叙述]:
在function里面使用switch时
[程式范例]:
比如说我想要
当fruit=apple
x=x[,2]
y=y[,2]
fruit=grape
x=x[,3]
y=y[,3]
则写成程式
data = function(x, fruit)
{
switch(fruit, apple=????
grape=????这个地方完全就不知道怎么打... )
}
if else又只能用在数字...
还是说除了switch之外,有其他[名词]条件选择的指令呢?
感谢各位大大
作者: celestialgod (天)   2015-11-16 22:56:00
什么是if else只能用在数字?if (fruit == 'apple') 还是可以做得到阿col = switch(a, apple = 2, grape = 3)再拿col做事就好了
楼主: laputaca (离歌笑)   2015-11-16 23:00:00
原来是我误会了XDDDD难怪我想破脑袋 感恩感恩

Links booklink

Contact Us: admin [ a t ] ucptt.com