Skip to content

Instantly share code, notes, and snippets.

@rpietro
Created September 9, 2013 14:41
Show Gist options
  • Save rpietro/6496558 to your computer and use it in GitHub Desktop.
Save rpietro/6496558 to your computer and use it in GitHub Desktop.
script to extract a random sample out of a dataset
# making the random sample reproducible, makes it easier to take other samples
set.seed(123)
# add your local path below
setwd("")
fulldat <- read.csv("fulldat.csv", header = TRUE)
#removing duplicates
fulldat <- fulldat[!duplicated(fulldat$var),]
str(fulldat)
#taking a random sample
datasamp <- fulldat[sample(1:nrow(fulldat), 1500, replace=FALSE),]
# saving a local file
write.csv(datasamp, "datasamp.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment