Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer)
(Answer)
Line 493: Line 493:
 
# Replace missing values with values from temp.
 
# Replace missing values with values from temp.
 
out[[rescol]] <- ifelse(is.na(out[[rescol]]), out$Result, out[[rescol]]) # Result comes from temp
 
out[[rescol]] <- ifelse(is.na(out[[rescol]]), out$Result, out[[rescol]]) # Result comes from temp
out$Result <- NULL
+
if(rescol != "Result") out$Result <- NULL
 
X@output <- out
 
X@output <- out
 +
return(X)
 +
}
 +
findrest <- function (X, cols, total = 1)
 +
{
 +
# 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.
 +
if (nrow(X@output) == 0)
 +
X <- EvalOutput(X)
 +
rescol <- comment(result(X))
 +
marginals <- colnames(X@output)[X@marginal]
 +
 +
# 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 <- unkeep(temp, cols = rescol) # Remove old rescol because it would cause trouble later.
 +
colnames(temp@output)[colnames(temp@output) == "Result"] <- "tempResult"
 +
temp@name <- "temp" # This is to make sure that merge works.
 +
print(temp)
 +
out <- merge(X, temp)@output
 +
 +
# Replace missing values with values from temp.
 +
out[[rescol]] <- ifelse(is.na(out[[rescol]]), out$tempResult, out[[rescol]]) # Result comes from temp
 +
out$tempResult <- NULL
 +
X@output <- out
 +
X@marginal <- colnames(X@output) %in% marginals
 
return(X)
 
return(X)
 
}
 
}
Line 505: Line 529:
  
 
for(i in cols) { # Give warning about unkept indices with >1 locations.
 
for(i in cols) { # Give warning about unkept indices with >1 locations.
if(length(unique(X@output[[i]])) > 1) {
+
if(
 +
length(unique(X@output[[i]])) > 1 &
 +
X@marginal[match(i, colnames(X@output))]
 +
) {
 
warning(paste(
 
warning(paste(
 
"There is >1 unique locations in column",  
 
"There is >1 unique locations in column",  

Revision as of 10:29, 27 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>