Hello I'm translating a Visual Basic routine to R. Which command in R is similar to "select case" in VB? See the example: select case int(AG) case 0, 5, 8, 10 VAR = 37 case 1, 4 VAR = 70 case 3, 6, 9 VAR = 90 case 2, 7 VAR = 112 end select A chain of "if else" would not be very elegant. Is there another option? Thanks in advance. Best regards. Antonio Olinto [[alternative HTML version deleted]]
? switch Might do the job. On Wed, Aug 31, 2011 at 1:27 PM, Antonio Silva <aolinto.lst@gmail.com>wrote:> Hello > > I'm translating a Visual Basic routine to R. > > Which command in R is similar to "select case" in VB? > > See the example: > > select case int(AG) > case 0, 5, 8, 10 > VAR = 37 > case 1, 4 > VAR = 70 > case 3, 6, 9 > VAR = 90 > case 2, 7 > VAR = 112 > end select > > A chain of "if else" would not be very elegant. Is there another option? > > Thanks in advance. Best regards. > > Antonio Olinto > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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]]
Hi Antonio, Take a look at require(car) ?recode for an alternative. HTH, Jorge On Wed, Aug 31, 2011 at 1:27 PM, Antonio Silva <> wrote:> Hello > > I'm translating a Visual Basic routine to R. > > Which command in R is similar to "select case" in VB? > > See the example: > > select case int(AG) > case 0, 5, 8, 10 > VAR = 37 > case 1, 4 > VAR = 70 > case 3, 6, 9 > VAR = 90 > case 2, 7 > VAR = 112 > end select > > A chain of "if else" would not be very elegant. Is there another option? > > Thanks in advance. Best regards. > > Antonio Olinto > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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]]