Commit 32eef4ee authored by Chris Jewell's avatar Chris Jewell
Browse files

Shortened k grooming code with reshape2

parent 5988d83b
......@@ -533,25 +533,11 @@ HaldDP <- R6::R6Class(
!all(k$Value >= 0) | !all(k$Value <= 1))
stop("All prevalence values must be numbers between 0 and 1.")
private$k <- array(
NA,
dim = c(private$nSources, private$nTimes),
dimnames = list(
source = private$namesSources,
time = private$namesTimes
)
private$k = tryCatch(
acast(k, Source ~ Time, value.var = 'Value'),
condition = function(c)
stop('Malformed k. Check Source/Time combinations for regularity.')
)
## Extract values from data frame and put into arrays. Surely this is very slow!! TODO: find better way!
for (time in private$namesTimes) {
for (sources in private$namesSources) {
tmp_k <- k$Value[which(k$Time == time & k$Source == sources)]
if (length(tmp_k) == 0L)
stop("k must have a non-NA row for each time and source.")
private$k[which(private$namesSources == sources), which(private$namesTimes == time)] <-
tmp_k
}
}
},
set_a_q = function(a_q)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment