[R] Interpretation of 'swtich'
Uwe Ligges
ligges at statistik.tu-dortmund.de
Sun Mar 7 17:52:30 CET 2010
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