... which raises an interesting point: What if some of the values are replicated? Does the OP want to have a random sample of everything or of the unique values?
Cheers, Bert On Wed, Oct 23, 2013 at 12:39 PM, Nordlund, Dan (DSHS/RDA) <nord...@dshs.wa.gov> wrote: >> -----Original Message----- >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >> project.org] On Behalf Of erinu >> Sent: Wednesday, October 23, 2013 11:14 AM >> To: r-help@r-project.org >> Subject: [R] How to view un-sampled data from a randomly sampled >> dataset >> >> Hi there- >> >> I have a 150 row dataset (data). I create "y" a randomly sampled >> (without >> replacement) set number of observations (40): >> >> y<-data[sample(1:nrow(data),40,replace=FALSE),] >> >> I would like to make a new variable "x" that contains the leftover >> non-sampled 110 observations. I am sure there is a fairly easy way to >> do >> this. >> >> Any help would be greatly appreciated. >> >> THANKS! >> >> > > Perhaps something like > > ndx <- sample(1:nrow(data),40,replace=FALSE) > y <- data[ndx,] > x <- data[-ndx,] > > > hope this is helpful, > > Dan > > Daniel J. Nordlund, PhD > Research and Data Analysis Division > Services & Enterprise Support Administration > Washington State Department of Social and Health Services > > > ______________________________________________ > 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. -- Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 ______________________________________________ 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.