Logic operators...more than one??

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Logic operators...more than one??

kydaviddoyle
I'm sure this is a simple question but I'm not sure where to find the
answer.

I want to remove some of the data.  For example when my Location column is
MW-09, MW-10, or MW-11.

It works fine if I ONLY list ONE of the locations as in:

SampledWells <- MyData[ MyData$Location != "MW-09", ]

But if I try to do more than one (as shown below), I don't get an error but
I also don't get my SampledWells
SampledWells <- MyData[ MyData$Location != "MW-09", "MW-10", ]

Thoughts??

Thank you for your time
David

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Take Care

David Doyle
Reply | Threaded
Open this post in threaded view
|

Re: Logic operators...more than one??

Jim Lemon-4
Hi David,
I think you want this:

SampledWells <- MyData[!( MyData$Location %in% c("MW-09", "MW-10")), ]

Jim

On Thu, Oct 4, 2018 at 9:02 AM David Doyle <[hidden email]> wrote:

>
> I'm sure this is a simple question but I'm not sure where to find the
> answer.
>
> I want to remove some of the data.  For example when my Location column is
> MW-09, MW-10, or MW-11.
>
> It works fine if I ONLY list ONE of the locations as in:
>
> SampledWells <- MyData[ MyData$Location != "MW-09", ]
>
> But if I try to do more than one (as shown below), I don't get an error but
> I also don't get my SampledWells
> SampledWells <- MyData[ MyData$Location != "MW-09", "MW-10", ]
>
> Thoughts??
>
> Thank you for your time
> David
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Logic operators...more than one??

R help mailing list-2
In reply to this post by kydaviddoyle

> On Oct 3, 2018, at 7:03 PM, David Doyle <[hidden email]> wrote:
>
> I'm sure this is a simple question but I'm not sure where to find the
> answer.
>
> I want to remove some of the data.  For example when my Location column is
> MW-09, MW-10, or MW-11.
>
> It works fine if I ONLY list ONE of the locations as in:
>
> SampledWells <- MyData[ MyData$Location != "MW-09", ]
>
> But if I try to do more than one (as shown below), I don't get an error but
> I also don't get my SampledWells
> SampledWells <- MyData[ MyData$Location != "MW-09", "MW-10", ]
>
> Thoughts??
>
> Thank you for your time
> David


Hi,

See ?"%in%"

Then:

  SampledWells <- MyData[ !MyData$Location %in% c("MW-09", "MW-10"), ]

Note the '!' operator that precedes the expression to negate the logical.

Regards,

Marc Schwartz


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Logic operators...more than one??

Bert Gunter-2
In reply to this post by kydaviddoyle
Inline.
-- 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 Wed, Oct 3, 2018 at 4:02 PM David Doyle <[hidden email]> wrote:

> I'm sure this is a simple question but I'm not sure where to find the
> answer.
>

Good R tutorials abound on the internet. One resource is:
https://www.rstudio.com/online-learning/#r-programming

but there are tons more if you search.

>
> I want to remove some of the data.  For example when my Location column is
> MW-09, MW-10, or MW-11.
>
> It works fine if I ONLY list ONE of the locations as in:
>
> SampledWells <- MyData[ MyData$Location != "MW-09", ]
>
> But if I try to do more than one (as shown below), I don't get an error but
> I also don't get my SampledWells
> SampledWells <- MyData[ MyData$Location != "MW-09", "MW-10", ]
>
> Thoughts??
>

?"%in%"

as in:

SampledWells <- MyData[ MyData$Location %in% c( "MW-09", "MW-10", "MW-11"),
]





> Thank you for your time
> David
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.