[R] remove from column a group of elements I have in another vector

Sarah Goslee sarah.goslee at gmail.com
Sat Dec 22 17:50:15 CET 2012


Well, you could try it to see what happens...

First look at:
b$ansologin%in%quit
then
!(b$ansologin%in%quit)
and finally
b[!(b$ansologin%in%quit),]

You could also read the help
?"!"
?"%in%"

and the Intro to R manual that came with R when you installed it.

Sarah

On Sat, Dec 22, 2012 at 10:48 AM, Estefanía Gómez Galimberti
<tefagg at yahoo.com> wrote:
> Thank you Sarah!!
>
> My data frame is b and I have to remove from column anslogin every value
> from vector quit
>
> b=
>     ht dispsplit anslogin month_
>   1038       162     4627      1
>    475         1     4305      1
>    205       103     4136      1
>    296         1     4627      1
>    784         9    51274      1
>   451        75     4593      1
>
> quit=
> 4079 4081 4095 4096 4119 4134
>
> So, i should do b[!(b$ansologin%in%quit),], right?
>
> How does the %in% work??? Is it a normal in and the not comes with the ! ate
> the beggining?   I have never used it, so thanks for teaching me this!.
>
> Thanks again,
> Estefania
>
> ________________________________
> From: Sarah Goslee <sarah.goslee at gmail.com>
> To: Estefanía Gómez Galimberti <tefagg at yahoo.com>
> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Friday, December 21, 2012 4:56 PM
> Subject: Re: [R] remove from column a group of elements I have in another
> vector
>
> You can probably do it with not in in R too:
> for a data frame x where you want to remove rows where values in
> column A are not in the vector y:
>
> x[!(x$A %in% y), ]
>
> If you'd provided a reproducible example, I could give code that works
> in your particular circumstance.
>
> Sarah
>
> On Fri, Dec 21, 2012 at 12:43 PM, Estefanía Gómez Galimberti
> <tefagg at yahoo.com> wrote:
>> Hi,
>>
>> I have a data frame and I would need to remove from one of
>> the columns a group of elements I have in another vector. How can I do
>> that? I know how to do it with criteria but i would need to do it in a more
>> automatic way....
>> In SQL I would use  where
>> ---- not in ----
>>
>> Thank you,
>> Estefania
>
> --

--
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list