[R] Remove Even Number from A Vector

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Sun Mar 3 07:43:12 CET 2019


Hi Darren,
You're probably looking for the %% (remainder) operator:

x<-1:10
# get odd numbers
x[as.logical(x%%2)]
# get even numbers
x[!(x%%2)]

Jim

On Sun, Mar 3, 2019 at 4:10 PM Darren Danyluk <Darren.Danyluk using sd6.bc.ca> wrote:
>
> Hello,
>
> I found this email when looking for some help with R Studio.  It's actually my daughter who is looking for help.
>
> It sounds like she is working with the very basics of this software, and her task is to write the code which would result in the extraction of "odd" data from a dataset of restaurant sales.
>
> This is a shot in the dark...please ignore if my question makes little or no sense.  I have no working knowledge of R software.
>
> Thanks.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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