[R] Interpretation of 'swtich'

rkevinburton at charter.net rkevinburton at charter.net
Sun Mar 7 23:26:31 CET 2010


Thatnk you.

The documentation indicates as you indicated that if there is not an exact match then the next element is chosen. But it does not indicate the case that contains an exact match but there is not value to be returned (=, case). From what you indicate this is treated as if it was not a match.

Kevin

---- Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote: 
> 
> 
> On 06.03.2010 21:49, rkevinburton at charter.net wrote:
> > In browsing the source I see the following construct:
> >
> >      res<- switch(type, working = , response = r, deviance = ,
> >          pearson = if (is.null(object$weights))
> >              r
> >          else r * sqrt(object$weights), partial = r)
> >
> > I understand that 'switch' will execute the code that is matched by its corresponding string value (in this case 'type'). What I don't understand is the empty code. Is this code saying that if the type is "deviance" then fill the 'res' variable with an empty value? From my naive point of view it seems that 'res' will only get a value(s) if 'type' is 'response', 'pearson', or 'partial'. Please help with my understanding.
> 
> Please do read the help pages!
> 
>  From ?switch:
> 
> "If there is an exact match then that element is evaluated and returned 
> if there is one, otherwise the next element is chosen, [...]"
> 
> Example:
> 
> switch("A", A=1, B=, C=2) # 1
> switch("B", A=1, B=, C=2) # 2
> 
> Uwe Ligges
> 
> 
> 
> > Kevin Burton
> > rkevinburton at charter.net
> >
> > ______________________________________________
> > R-help at 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.



More information about the R-help mailing list