-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor predictInterval for memory efficiency
- Loading branch information
Showing
7 changed files
with
133 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#Helpers | ||
|
||
# Function to take only rows that form distinct levels of factors | ||
trimModelFrame <- function(data){ | ||
# Identify numerics | ||
nums <- sapply(data, is.numeric) | ||
vars <- names(nums[!nums == TRUE]) | ||
dataList <- vector(mode = "list", length = length(vars)) | ||
names(dataList) <- vars | ||
for(i in vars){ | ||
dataList[[i]] <- data[!duplicated(data[, i]),] | ||
} | ||
newdat <- do.call(rbind, dataList) | ||
newdat <- newdat[!duplicated(newdat),] | ||
return(newdat) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test helper functions | ||
|
||
context("Trimming data frame") | ||
|
||
|
||
|
||
test_that("Trimming results in correct size", { | ||
data(InstEval) | ||
trimDat <- trimModelFrame(InstEval) | ||
expect_more_than(nrow(InstEval), nrow(trimModelFrame(InstEval))) | ||
expect_equal(nrow(trimDat), 4065) | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
library(microbenchmark) | ||
|
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