OpasnetUtils/Orbind: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 12: Line 12:
label="Initiate functions"
label="Initiate functions"
graphics="1"
graphics="1"
showcode="1"
>
>
# ORBIND ########################### orbind combines two ovariables using clever rbind
# ORBIND ########################### orbind combines two ovariables using clever rbind

Revision as of 10:50, 15 June 2012



Description

orbind combines two ovariables using clever rbind

Code

- Hide code

# ORBIND ########################### orbind combines two ovariables using clever rbind

orbind <- function(x, y) {
		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.
	}

See also