R语言switch语句报错Error: duplicate ‘switch‘ defaults

解决方法

对于数值型:

print(switch(3,"h1","h2","h3","h4")) # 打印 h3
print(switch(5,"h1","h2","h3","h4")) # 打印 NULL

对于字符串类型:

print(switch("x3",x1 = "h1",x2 = "h2",x3 = "h3",x4 = "h4")) # 打印“h3”

问题解析

如果匹配字符串类型时不指定 x1 = "h1",x2 = "h2",x3 = "h3",x4 = "h4"这些内容会报错:Error: duplicate 'switch' defaults

猜你喜欢

转载自blog.csdn.net/weixin_35757704/article/details/114261052
今日推荐