Skip to content

Instantly share code, notes, and snippets.

@t-student
Created November 10, 2015 09:53
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 t-student/b93167cf529607038406 to your computer and use it in GitHub Desktop.
Save t-student/b93167cf529607038406 to your computer and use it in GitHub Desktop.
# > head(df1, 2)
# id cartvol0 cartvol1 incr.cart interval diff
# 1 1 1.987862 2.023709 Yes 3 0.03584695
# 2 2 1.694808 1.584858 No 2 -0.10995007
df1$diff <- df1$cartvol1 - df1$cartvol0
v <- as.numeric(quantile(df1$cartvol0, c(0.3333, 0.6667)))
df1$interval <- as.factor(findInterval(df1$cartvol0, v)+1)
ddply(df1, .(interval), summarise, diff.mean = mean(diff, na.rm = T), n = length(diff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment