Dear all,> data <- data.frame(id=seq(1:10),x=runif(10)) > dataid x 1 1 0.3604464 2 2 0.4813987 3 3 0.0160058 4 4 0.7165909 5 5 0.6092248 6 6 0.2413049 7 7 0.7981568 8 8 0.6093960 9 9 0.2887064 10 10 0.3485780> selected.id <- sample(data$id,3,replace=F) > selected.id[1] 9 7 1 I want to select data with corresponding selected.id, namely> selected.dataid x 9 9 0.2887064 7 7 0.7981568 1 1 0.3604464 How to do? Tq. Abdul Kudus Institute for Mathematical Research Universiti Putra Malaysia [[alternative HTML version deleted]]
data[data$id==selected$id, ] ------------------------- 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 abdul kudus Gesendet: Wednesday, May 06, 2009 12:42 AM An: r-help at r-project.org Betreff: [R] subset data Dear all,> data <- data.frame(id=seq(1:10),x=runif(10)) > dataid x 1 1 0.3604464 2 2 0.4813987 3 3 0.0160058 4 4 0.7165909 5 5 0.6092248 6 6 0.2413049 7 7 0.7981568 8 8 0.6093960 9 9 0.2887064 10 10 0.3485780> selected.id <- sample(data$id,3,replace=F) selected.id[1] 9 7 1 I want to select data with corresponding selected.id, namely> selected.dataid x 9 9 0.2887064 7 7 0.7981568 1 1 0.3604464 How to do? Tq. Abdul Kudus Institute for Mathematical Research Universiti Putra Malaysia [[alternative HTML version deleted]] ______________________________________________ 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.
Like this? data<-read.table(stdin(), head=T, sep=",") id,x 1,0.3604464 2,0.4813987 3,0.0160058 4,0.7165909 5,0.6092248 6,0.2413049 7,0.7981568 8,0.6093960 9,0.2887064 10,0.3485780 selected.id <- sample(data$id,3,replace=F) selected.id data.subset<-subset(data, id %in% selected.id) data.subset Cheers milton On Wed, May 6, 2009 at 12:42 AM, abdul kudus <abdul.kudus@gmail.com> wrote:> Dear all, > > > data <- data.frame(id=seq(1:10),x=runif(10)) > > data > id x > 1 1 0.3604464 > 2 2 0.4813987 > 3 3 0.0160058 > 4 4 0.7165909 > 5 5 0.6092248 > 6 6 0.2413049 > 7 7 0.7981568 > 8 8 0.6093960 > 9 9 0.2887064 > 10 10 0.3485780 > > selected.id <- sample(data$id,3,replace=F) > > selected.id > [1] 9 7 1 > > I want to select data with corresponding selected.id, namely > > > selected.data > id x > 9 9 0.2887064 > 7 7 0.7981568 > 1 1 0.3604464 > > How to do? > > Tq. > > Abdul Kudus > Institute for Mathematical Research > Universiti Putra Malaysia > > [[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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Try, data[data$id%in%selected.id,] Good day! Kushantha -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of abdul kudus Sent: Wednesday, May 06, 2009 10:12 AM To: r-help at r-project.org Subject: [R] subset data Dear all,> data <- data.frame(id=seq(1:10),x=runif(10)) > dataid x 1 1 0.3604464 2 2 0.4813987 3 3 0.0160058 4 4 0.7165909 5 5 0.6092248 6 6 0.2413049 7 7 0.7981568 8 8 0.6093960 9 9 0.2887064 10 10 0.3485780> selected.id <- sample(data$id,3,replace=F) > selected.id[1] 9 7 1 I want to select data with corresponding selected.id, namely> selected.dataid x 9 9 0.2887064 7 7 0.7981568 1 1 0.3604464 How to do? Tq. Abdul Kudus Institute for Mathematical Research Universiti Putra Malaysia [[alternative HTML version deleted]] ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}}
Or somewhat more readibly selected.data <- subset(data, id %in% selected.id) Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kushantha Perera Sent: Wednesday, 6 May 2009 3:15 PM To: abdul kudus; r-help at r-project.org Subject: Re: [R] subset data Try, data[data$id%in%selected.id,] Good day! Kushantha -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of abdul kudus Sent: Wednesday, May 06, 2009 10:12 AM To: r-help at r-project.org Subject: [R] subset data Dear all,> data <- data.frame(id=seq(1:10),x=runif(10)) > dataid x 1 1 0.3604464 2 2 0.4813987 3 3 0.0160058 4 4 0.7165909 5 5 0.6092248 6 6 0.2413049 7 7 0.7981568 8 8 0.6093960 9 9 0.2887064 10 10 0.3485780> selected.id <- sample(data$id,3,replace=F) > selected.id[1] 9 7 1 I want to select data with corresponding selected.id, namely> selected.dataid x 9 9 0.2887064 7 7 0.7981568 1 1 0.3604464 How to do? Tq. Abdul Kudus Institute for Mathematical Research Universiti Putra Malaysia [[alternative HTML version deleted]] ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} ______________________________________________ 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.