Skip to content

Instantly share code, notes, and snippets.

@mbannert
Created November 29, 2014 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbannert/95367d5d5b7cc1e5d75a to your computer and use it in GitHub Desktop.
Save mbannert/95367d5d5b7cc1e5d75a to your computer and use it in GitHub Desktop.
reproducible example to split dataset into intervals when sorted
# generate data, variables will be name X1 .... X8
# dimension: 1200 rows, 7 cols
daten <- data.frame(matrix(rnorm(8400),ncol = 7))
# 8th col is just sequential id 1-1200
daten$id <- as.numeric(row.names(daten))
# assume data are sorted,
# add another column that indicates
# the subset
x <- integer()
for(i in 1:10) x <- c(x,rep(i,120))
daten$subset <- x
# do the split trick
lapply(split(daten,factor(daten$subset)),
summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment