Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer)
(Answer: findrest corrected)
Line 478: Line 478:
 
}
 
}
  
findrest <- function(X, cols, total = 1) {
+
findrest <- function (X, cols, total = 1)  
 +
{
 
# findrest input is an ovariable that can be integrated over indices cols to result in total.
 
# findrest input is an ovariable that can be integrated over indices cols to result in total.
 
# Often it is used with uncertain fractions. The largest fraction is omitted or NA, and it is replaced by whatever is missing from the total.
 
# Often it is used with uncertain fractions. The largest fraction is omitted or NA, and it is replaced by whatever is missing from the total.
+
if (nrow(X@output) == 0)  
if(nrow(X@output) == 0) X <- EvalOutput(X)
+
X <- EvalOutput(X)
 
rescol <- comment(result(X))
 
rescol <- comment(result(X))
marginal <- colnames(X@output)[X@marginal]
+
 
 
 
# temp is the amount that is still missing from the total.
 
# temp is the amount that is still missing from the total.
 
temp <- total - oapply(X, cols = cols, FUN = function(x) sum(x, na.rm = TRUE))
 
temp <- total - oapply(X, cols = cols, FUN = function(x) sum(x, na.rm = TRUE))
 
temp@output[[rescol]] <- NULL # Remove old rescol because it would cause trouble later.
 
temp@output[[rescol]] <- NULL # Remove old rescol because it would cause trouble later.
+
out <- merge(X, temp)@output
out <- merge(X, temp)
+
 
 
 
# Replace missing values with values from temp.
 
# Replace missing values with values from temp.
result(out) <- ifelse(is.na(out@output[[rescol]]), result(out), out@output[[rescol]])
+
out[[rescol]] <- ifelse(is.na(out[[rescol]]), out$Result, out[[rescol]]) # Result comes from temp
out@marginal <- colnames(out@output) %in% c(marginal, cols, gsub(" ", ".", cols))
+
out$Result <- NULL
return(out)
+
X@output <- out
 +
return(X)
 
}
 
}
  

Revision as of 20:49, 24 January 2014



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

Call the objects stored by this code from another rode with this command:

objects.latest("Op_en6007", code_name = "answer")

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>