Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer)
(Answer)
Line 54: Line 54:
  
 
# fillna takes a data.frame and fills the cells with NA with each level in that column.
 
# fillna takes a data.frame and fills the cells with NA with each level in that column.
# object is the data.frame, marginals is a vector of columns (either column names or positions) that are to be filled.
+
# fillna was updated in OpasnetUtils and therefore removed from here.
# This version of fillna accepts column positions (as the previous version) and also column names in marginals.
 
  
fillna <- function (object, marginals) {
 
a <- dropall(object)
 
if(!is.numeric(marginals)) marginals <- match(marginals, colnames(object))
 
for (i in marginals) {
 
a[[i]] <- as.factor(a[[i]])
 
a1 <- a[!is.na(a[[i]]), ]
 
a2 <- a[is.na(a[[i]]), ][-i]
 
addition <- data.frame(A = levels(a[[i]]))
 
colnames(addition) <- colnames(a)[i]
 
a2 <- merge(addition, a2)
 
a <- rbind(a1, a2)
 
}
 
return(a)
 
}
 
  
 
## collapsemarg is a placeholder for a better functionality within CollapseMarginals.
 
## collapsemarg is a placeholder for a better functionality within CollapseMarginals.
Line 676: Line 661:
 
}
 
}
  
continuousOps <- function(O1, O2, cols, fun)
+
objects.store(ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, truncateIndex, findrest,  
{
+
unkeep, timing, makeTimeline)
# continuousOps merges two ovariables by continuous indices and preforms an operation.
 
# O1, O2 are ovariables. All locations in O1 are created for O2 assuming that the previous value applies.
 
# Note that this is unsymmertric. Locations in O2 that are missing from O1 are omitted.
 
# cols are the common indices used in merge. They must be continous (numeric). Other common indices will cause trouble.
 
# fun is the function that is performed after merge. Typically it is '*', '+' or some other Ops.
 
 
rescol <- paste(O2@name, "Result", sep = "")
 
 
out <- merge(
 
unique(O1@output[cols]),
 
O2@output[c(cols, rescol)],
 
all.x = TRUE
 
) # Also automatically sorts the output by cols.
 
 
for(i in 2:nrow(out))
 
{
 
if(is.na(out[i, rescol])) out[i, rescol] <- out[i - 1, rescol]
 
}
 
 
out <- unique(out[!is.na(out[rescol]) , ]) # removes all rows that are before the first location in O2.
 
out <- Ovariable(name = sub("Result$", "", rescol), output = out, marginal = colnames(out) %in% cols)
 
out <- get(fun)(O1, out)
 
 
 
return(out)
 
}
 
 
 
 
 
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, truncateIndex, findrest,  
 
unkeep, timing, makeTimeline, continuousOps)
 
  
cat(paste("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML,",
+
cat(paste("The following objects are stored: ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML,",
"truncateIndex, findrest, unkeep, timing, makeTimeline, continuousOps.\n"))
+
"truncateIndex, findrest, unkeep, timing, makeTimeline.\n"))
  
 
</rcode>
 
</rcode>

Revision as of 12:52, 6 February 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>