Hi Megh, You're right. It happens because the replications of some elements of your vector x are "removed" once you put the condition. So, when you type table(x) and table(x1), you'll have something like this:
# x # 68 72 80 84 88 92 96 100 # 2 2 1 2 5 2 3 3 # x1 # 88 92 96 # 2 2 1 length(x) is 20 and length(x1) is 5, but when you type x[!x%in%x1] you're removing the elements of x that are present in x1, *including* replications. I just read Peter Dalgaard's reply while I was writing this email. If you are interested in "what "remains" when you remove a value that occurs multiple times in x", as he said, just follow his advice. HTH, Jorge On Sat, Oct 11, 2008 at 3:46 PM, Megh Dal <[EMAIL PROTECTED]> wrote: > Thanks for this suggestion. However I am not getting : > > length(x) = length(x1) + length(x[ ! x %in% x1]) > > Any better idea? > > > --- On Sun, 10/12/08, Jorge Ivan Velez <[EMAIL PROTECTED]> wrote: > > > From: Jorge Ivan Velez <[EMAIL PROTECTED]> > > Subject: Re: [R] Extracting subset of a vector > > To: [EMAIL PROTECTED] > > Cc: [EMAIL PROTECTED] > > Date: Sunday, October 12, 2008, 1:06 AM > > Hi Megh, > > Try this: > > > > x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) > > x1 = sample(x, 5, replace=FALSE) > > > > x[ ! x %in% x1] > > > > HTH, > > > > Jorge > > > > > > On Sat, Oct 11, 2008 at 3:25 PM, Megh Dal > > <[EMAIL PROTECTED]> wrote: > > > > > I have 2 vecros : > > > > > x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) > > > x1 = sample(x, 5, replace=FALSE) > > > > > > Now i want to get remaining values of vector > > "x" those are not member of > > > vector "x1". Can anyone please tell me how > > to do that? > > > > > > ______________________________________________ > > > 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. > > > > > > > [[alternative HTML version deleted]] ______________________________________________ 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.