OpasnetUtils/Orbind: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
(code replaced with link to code)
 
Line 8: Line 8:


==Code==
==Code==
<rcode
name="answer"
label="Initiate functions"
graphics="1"
showcode="1"
>
# ORBIND ########################### orbind combines two ovariables using clever rbind


orbind <- function(x, y) {
https://www.opasnet.org/svn/opasnet_utils/trunk/R/ORBind.r
if(class(x) == "ovariable") {xoutput <- x@output} else {xoutput <- x}
if(class(y) == "ovariable") {youtput <- y@output} else {youtput <- y}
cols <- setdiff(colnames(youtput), colnames(xoutput)) # Take all columns that do not exist in x and add them.
col <- as.data.frame(array("NA", dim = c(1, length(cols))))
colnames(col) <- cols
if("Unit" %in% cols) {col[, "Unit"] <- "?"}
temp <- cbind(xoutput, col)
 
cols <- setdiff(colnames(xoutput), colnames(youtput)) # Take all columns that do not exist in y and add them.
col <- as.data.frame(array("NA", dim = c(1, length(cols))))
colnames(col) <- cols
if("Unit" %in% cols) {col[, "Unit"] <- "?"}
xoutput <- rbind(temp, cbind(youtput, col)) # Combine x and y with rbind.
return(xoutput)
#Should this be made S4 function for ovariables? Then it could be named simply rbind.
}
 
</rcode>


==See also==
==See also==

Latest revision as of 13:45, 16 August 2012



Description

orbind combines two ovariables using clever rbind

Code

https://www.opasnet.org/svn/opasnet_utils/trunk/R/ORBind.r

See also