Hi, The help page for subset states "subset: logical expression indicating elements or rows to keep: missing values are taken as false." Before I try to re-invent the wheel, I would like to know if one of the base or recommended packages would contain a variant of the subset function that would consider missing values as true. Thanks
Please read the "Details" section of the help file -- it essentially tells you what to do by directly using indexing; e.g. for a vector, index by: [is.na(subset) | subset] . Adjust as necessary for your data structure.Or look at the code of, e.g. subset.data.frame and create your own subset version/method by making the trivial modification to that code. R is open source. Sometimes it's worthwhile to take advantage of this by making a simple modification to its code on your own before hunting for packages. Cheers, Bert Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Apr 8, 2018 at 9:06 PM, Sebastien Bihorel <sebastien.bihorel at cognigencorp.com> wrote:> Hi, > > The help page for subset states "subset: logical expression indicating elements or rows to keep: missing values are taken as false." > > Before I try to re-invent the wheel, I would like to know if one of the base or recommended packages would contain a variant of the subset function that would consider missing values as true. > > Thanks > > ______________________________________________ > 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.
Sent from my iPhone> On Apr 8, 2018, at 9:06 PM, Sebastien Bihorel <sebastien.bihorel at cognigencorp.com> wrote: > > Hi, > > The help page for subset states "subset: logical expression indicating elements or rows to keep: missing values are taken as false." > > Before I try to re-invent the wheel, I would like to know if one of the base or recommended packages would contain a variant of the subset function that would consider missing values as true. >Just use a Boolean expression is.na(col)|(col==0)> Thanks > > ______________________________________________ > 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.
Thanks. S. Elison provided a similar but apparently more general solution (see other post in thread). ----- Original Message ----- From: "David Winsemius" <dwinsemius at comcast.net> To: "Sebastien Bihorel" <sebastien.bihorel at cognigencorp.com> Cc: r-help at r-project.org Sent: Monday, April 9, 2018 12:33:41 AM Subject: Re: [R] Question about subset Sent from my iPhone> On Apr 8, 2018, at 9:06 PM, Sebastien Bihorel <sebastien.bihorel at cognigencorp.com> wrote: > > Hi, > > The help page for subset states "subset: logical expression indicating elements or rows to keep: missing values are taken as false." > > Before I try to re-invent the wheel, I would like to know if one of the base or recommended packages would contain a variant of the subset function that would consider missing values as true. >Just use a Boolean expression is.na(col)|(col==0)> Thanks > > ______________________________________________ > 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.