Sender: r-help-boun...@r-project.org
On-Behalf-Of: mailinglist.honey...@gmail.com
Subject: Re: [R] vector help
Message-Id: <2154bd29-add9-4cfc-8447-ba5eea3a3...@gmail.com>
Recipient: yingmei.la...@magnetar.com
--- Begin Message ---
Hi Ramya,

On Dec 10, 2009, at 3:29 PM, David Winsemius wrote:

> 
> On Dec 10, 2009, at 2:55 PM, Ramya wrote:
> 
>> 
>> I have tow vectors one is the subset of another
>> 
>> x is a subset of X Both are vectors with n elements
>> 
>> X[X %in% x] would give me x again rite because it is a subset but i want all
>> those are not in x from X.
>> 
>> X[which(X != x)] should this do that

One way to increase your proficiency in R is to break out your statements so 
that each line does 1 thing.

You should look at the object that `X != x` returns to you. [Shuffle the 
elements in X and x and then see how that changes for extra credit]

Then look at what `which(X != x)` gives you.

Doing that, you'd see why what you tried originally didn't work.

> 
> Perhaps you think R _should_ read your mind, but we are not there yet. Try 
> instead:
> 
> X[!(X %in% x)]

There are also set-like functions in R, which might fit your brain-way of 
thinking:

Get elements that are in both x and X:
intersect(X,x)

Get elements in X that are not in x
setdiff(X,x)


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

______________________________________________
R-help@r-project.org mailing list
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.

--- End Message ---
______________________________________________
R-help@r-project.org mailing list
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 via email to