Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer: new version of fillna added)
(Answer: collapsemarg added)
Line 11: Line 11:
 
==Answer==
 
==Answer==
  
<rcode name="answer">
+
<rcode name="answer" embed=1>
  
 
library(OpasnetUtils)
 
library(OpasnetUtils)
Line 68: Line 68:
 
}
 
}
  
objects.store(ograph, fillna)
+
## collapsemarg is a placeholder for a better functionality within CollapseMarginals.
 +
## It takes an ovariable, and summarises all but given marginals using tapply and a user-defined function.
 +
## The output is an ovariable with the same name as the input.
 +
## This was first created for [[:op_fi:Radonin terveysvaikutukset]]
  
cat("The following objects are stored: ograph, fillna\n")
+
collapsemarg <- function(object, marginals, fun = sum) {
 +
 
 +
object@output <- dropall(object@output)
 +
 
 +
temp <- as.data.frame(as.table(tapply(result(object), object@output[marginals], fun)))
 +
 
 +
colnames(temp)[colnames(temp) == "Freq"] <- "Result"
 +
 
 +
out <- EvalOutput(Ovariable(object@name, data = temp))
 +
 
 +
return(out)
 +
}
 +
 
 +
 
 +
objects.store(ograph, fillna, collapsemarg)
 +
 
 +
cat("The following objects are stored: ograph, fillna, collapsemarg.\n")
  
 
</rcode>
 
</rcode>

Revision as of 08:21, 17 November 2013



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

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>