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?
Hi Megh, two options: x=1:20 y=1:10 z1=x[x%in%y==FALSE] z2=x[x!=y] z1 z2 Cheers, Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Megh Dal Gesendet: Saturday, October 11, 2008 3:26 PM An: r-help at stat.math.ethz.ch Betreff: [R] Extracting subset of a vector 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 at 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.
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 <megh700004@yahoo.com> 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]]
Megh Dal 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? > >x[!(x %in% x1)] should do it. (Had it not been for the duplicates, setdiff(x,x1) should work too.) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
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 <jorgeivanvelez at gmail.com> wrote:> From: Jorge Ivan Velez <jorgeivanvelez at gmail.com> > Subject: Re: [R] Extracting subset of a vector > To: megh700004 at yahoo.com > Cc: r-help at stat.math.ethz.ch > 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 > <megh700004 at yahoo.com> 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 at 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. > >
Work with the indices.> x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) > x1 <- sample(length(x), 5, replace=FALSE) > x1[1] 18 20 12 11 1> length(x.new)> x[x1] # selected[1] 88 88 92 88 100> x.new <- x[-x1] # remove sampled values > x.new[1] 96 88 100 100 96 80 68 92 96 68 84 84 88 72 72> length(x)[1] 20> length(x1)[1] 5> length(x.new)[1] 15>On Sat, Oct 11, 2008 at 3:46 PM, Megh Dal <megh700004 at yahoo.com> 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 <jorgeivanvelez at gmail.com> wrote: > >> From: Jorge Ivan Velez <jorgeivanvelez at gmail.com> >> Subject: Re: [R] Extracting subset of a vector >> To: megh700004 at yahoo.com >> Cc: r-help at stat.math.ethz.ch >> 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 >> <megh700004 at yahoo.com> 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 at 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. >> > > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?