Skip to content

Commit

Permalink
Thinking about complete grids
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 12, 2013
1 parent d74154c commit b1e2a3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/condensed.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ condensed <- function(groups, grouped, summary) {
for (i in seq_along(groups)) {
attr(grouped[[i]], "width") <- groups[[i]]$width()
attr(grouped[[i]], "origin") <- groups[[i]]$origin()
attr(grouped[[i]], "nbins") <- groups[[i]]$nbins()
}

names(summary) <- paste0(".", names(summary))
Expand Down
11 changes: 11 additions & 0 deletions R/smooth.r
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ smooth <- function(x, h, var = summary_vars(x)[1], grid = NULL, type = "mean",
out[[var]] <- z
structure(out, class = c("condensed", class(out)))
}

complete_grid <- function(df) {
stopifnot(is.data.frame(df))

breaks <- function(width, origin, nbins) {
origin + width * seq.int(nbins)
}

cols <- lapply(df, function(x) do.call(breaks, attributes(x)))
expand.grid(cols, KEEP.OUT.ATTRS = FALSE)
}

0 comments on commit b1e2a3a

Please sign in to comment.