R language switch statement error error: duplicate'switch' defaults

Solution

For numeric type:

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

For string types:

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

Problem resolution

If no matching string type x1 = "h1",x2 = "h2",x3 = "h3",x4 = "h4"content will complain:Error: duplicate 'switch' defaults

Guess you like

Origin blog.csdn.net/weixin_35757704/article/details/114261052