[R] Interpretation of 'swtich'
Duncan Murdoch
murdoch at stats.uwo.ca
Mon Mar 8 13:08:21 CET 2010
Duncan Murdoch wrote:
> On 07/03/2010 5:26 PM, rkevinburton at charter.net wrote:
>
>> 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.
>>
>
> I think the writing is not very clear (and Brian Ripley has improved it
> in R-devel), but it does intend to say:
>
> - If there is an exact match with a value, then that value is returned.
>
Re-reading it, I think my clarification is unclear. The matching occurs
to the argument name. I should have written:
- If there is an exact match to an argument name with an associated
value, then that value is returned.
Duncan Murdoch
> - If there is an exact match with no value, then the next value is
> returned.
> - If there is no match, then the 1st unnamed arg (or 2nd if EXPR isn't
> named) is returned.
>
> I think this is different from your interpretation.
>
> Duncan Murdoch
>
>
>> 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.
>>>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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