Created
September 9, 2013 14:41
-
-
Save rpietro/6496558 to your computer and use it in GitHub Desktop.
script to extract a random sample out of a dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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