Difference between revisions of "OpasnetUtils/Orbind"

From Testiwiki
Jump to: navigation, search
(Created page with "Category:Opasnet Category:R tools {{method|moderator=|stub=Yes}} ==Description== orbind combines two ovariables using clever rbind ==Code== <rcode name="answer" lab...")
 
(code replaced with link to code)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[Category:Opasnet]]
 
[[Category:Opasnet]]
 
[[Category:R tools]]
 
[[Category:R tools]]
 +
[[Category:OpasnetUtils]]
 
{{method|moderator=|stub=Yes}}
 
{{method|moderator=|stub=Yes}}
  
Line 7: Line 8:
  
 
==Code==
 
==Code==
<rcode
 
name="answer"
 
label="Initiate functions"
 
graphics="1"
 
>
 
library(OpasnetBaseUtils)
 
library(xtable)
 
  
n <- 5
+
https://www.opasnet.org/svn/opasnet_utils/trunk/R/ORBind.r
 
 
# 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.
 
}
 
 
 
</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