1 and 2 are not valid identifiers in R, so you need to surround them with backticks to make them valid, the same as quoting a string:
switch(Stst, `1` = print("NO"), `2` = print("YES")) On Wed., Sep. 7, 2022, 14:35 akshay kulkarni, <akshay...@hotmail.com> wrote: > Dear members, > The following is my code: > > > Stst <- 2 > > switch(Stst, 1 = print("NO"), 2 = print("YES")) > Error: unexpected '=' in "switch(Stst, 1 =" > > Why isn't it printing "YES" on to the console? > > many thanks in advance. > > Thanking you, > Yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.