Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer: better version of collapsemarg, also contains pick)
(Answer: unkeep added)
Line 71: Line 71:
 
## It takes an ovariable, and summarises all indices in cols using tapply and a user-defined function.
 
## It takes an ovariable, and summarises all indices in cols using tapply and a user-defined function.
 
## However, you can also use function "pick" to select locations defined in a list picks found in indices cols.
 
## However, you can also use function "pick" to select locations defined in a list picks found in indices cols.
 +
## Function "unkeep" simply drops the unkept indices without any other operation.
 
## The output is an ovariable with the same name as the input.
 
## The output is an ovariable with the same name as the input.
 
## This was first created for [[:op_fi:Radonin terveysvaikutukset]]
 
## This was first created for [[:op_fi:Radonin terveysvaikutukset]]
Line 77: Line 78:
 
out <- dropall(variable@output)
 
out <- dropall(variable@output)
 
marginals <- colnames(out)[variable@marginal]
 
marginals <- colnames(out)[variable@marginal]
margtemp <- colnames(out)[colnames(out) %in% marginals & !colnames(out) %in% cols] # You must leave at least one index.
 
  
if(tolower(fun) == "pick") { # The function must be a string, otherwise this row will fail.
+
if(tolower(fun) == "unkeep") { # The function must be a string, otherwise this row will fail.
for(i in cols) {
+
out <- out[!colnames(out) %in% cols]
out <- out[out[[i]] %in% picks[[match(i, cols)]] , ]
 
}
 
 
} else {
 
} else {
out <- as.data.frame(as.table(tapply(result(variable), out[margtemp], fun)))
+
if(tolower(fun) == "pick") {
out <- out[!is.na(out$Freq) , ]
+
for(i in cols) {
 +
out <- out[out[[i]] %in% picks[[match(i, cols)]] , ]
 +
}
 +
} else {
 +
margtemp <- colnames(out)[colnames(out) %in% marginals & !colnames(out) %in% cols]  
 +
# You must leave at least one index.
  
colnames(out)[colnames(out) == "Freq"] <- ifelse(
+
out <- as.data.frame(as.table(tapply(result(variable), out[margtemp], fun)))
length(variable@name) == 0,  
+
out <- out[!is.na(out$Freq) , ]
"Result",  
+
 
paste(variable@name, "Result", sep = "")
+
colnames(out)[colnames(out) == "Freq"] <- ifelse(
)
+
length(variable@name) == 0,  
 +
"Result",  
 +
paste(variable@name, "Result", sep = "")
 +
)
 +
}
 
}
 
}
  

Revision as of 19:59, 19 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>