Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer: ovaMatrixProduct added)
(Answer: bug fixed)
Line 11: Line 11:
 
==Answer==
 
==Answer==
  
<rcode name="answer" embed=0>
+
<rcode name="answer" embed=1>
  
 
library(OpasnetUtils)
 
library(OpasnetUtils)
Line 450: Line 450:
 
}
 
}
  
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, ovaMatrixProduct)
+
# Merge all but show_bins largest bins of indices cols to 'Other'.
  
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, ovaMatrixProduct.\n")
+
truncateIndex <- function( # Truncates an index to contain only the largest index bins.
 +
obj, # ovariable to use.
 +
cols, # names of the columns to truncate.
 +
bins = 10# Number of bins to show. Other bins will be merged to "Other".
 +
) {
 +
for(i in 1:length(cols))
 +
{
 +
sums <- as.data.frame(as.table(tapply(result(obj), obj@output[cols[i]], sum)))
 +
bins <- min(bins, length(levels(obj@output[[cols[i]]])))
 +
limit <- sort(sums$Freq, decreasing = TRUE)[bins]
 +
keeps <- sums[sums$Freq > limit , cols[i]]
 +
keeps <- levels(keeps)[keeps]
 +
 
 +
levels(obj@output[[cols[i]]]) <- ifelse(
 +
levels(obj@output[[cols[i]]]) %in% keeps,
 +
levels(obj@output[[cols[i]]]),
 +
"Other"
 +
)
 +
}
 +
return(obj)
 +
}
 +
 
 +
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, ovaMatrixProduct, truncateIndex)
 +
 
 +
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, ovaMatrixProduct, truncateIndex.\n")
  
 
</rcode>
 
</rcode>

Revision as of 07:00, 28 December 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>