Created
October 15, 2014 23:53
-
-
Save jfaganUK/0f0e26202aefc0da04f5 to your computer and use it in GitHub Desktop.
sqldf random filtering
This file contains 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
library(sqldf) | |
# there is a default dataset called iris that is always loaded into the R scope | |
# let's say I want to break it into two randomly using sqldf | |
# assign id's to the rows | |
my.iris <- iris | |
my.iris$id <- 1:nrow(my.iris) | |
ran.split <- data.frame(rs = sample(1:max(my.iris$id), floor(max(my.iris$id) / 2), replace=F)) | |
sqldf("select * from `my.iris` as x inner join `ran.split` as y on x.id = y.rs") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment