[R] Subsetting data with svyglm

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Feb 12 05:49:39 CET 2015


This seems like a fundamental  misunderstanding on your part of how operators, and in particular logical expressions, work in computer languages. Consider some examples:

1+2 has a numeric answer because 1 and 2 are both numeric.
1+"a" has at the very least not a numeric answer because the values on either side of the "+" sign are not both numeric.
TRUE | FALSE  has a logical type of answer because both sides of the logical "or" operator are logical.
However, you are expressing something like
TRUE | "a string" which might mean something but that something generally is not a logical type of answer.

Try
variable=="value a" | variable=="value b"
or
variable %in% c( "value a", "value b" )

You would probably find that the Introduction to R document that comes with R has some enlightening examples in it. You might also find Pat Burns' "The R Inferno" entertaining as well (search for it in your favorite search engine).
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On February 11, 2015 8:42:58 PM EST, Brennan O'Banion <brennan.obanion at gmail.com> wrote:
>I am aware that it is possible to specify a subset with a single
>logical operator when constructing a model, such as:
>svyglm(formula, design=data, subset=variable=="value").
>
>What I can't figure out is how to specify a subset with two or more
>logical operators:
>svyglm(formula, design=data, subset=variable=="value a"|"value b").
>
>Is it possible to specify a subset in this way using *glm without
>having to, in my case, subset the original data, create a survey
>design, and then fit a model?
>
>______________________________________________
>R-help at 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.



More information about the R-help mailing list