【发布时间】:2017-07-01 16:03:33
【问题描述】:
The below results in an error:
a = 3
switch(a,
1 = {print(1)},
2 = {print(2)},
3 = {print(3)},
{print("null")}
)
> source('~/.active-rstudio-document', echo=TRUE)
Error in source("~/.active-rstudio-document", echo = TRUE) :
~/.active-rstudio-document:3:10: unexpected '='
2: switch(a,
3: 1 =
^
为什么在上述情况下不能使用整数值? switch 只对字符有效吗?
【问题讨论】:
-
并不是不能使用整数。 switch 语句的语法错误。请输入
?switch并阅读文档。
标签: r switch-statement conditional rstudio