If x1
is NULL x2
is returned otherwise cbind(x1, x2)
safeColumnBind(x1, x2)
x1 | first object to be passed to |
---|---|
x2 | second object to be passed to |
result of cbind(x1, x2)
or x2
if x1
is NULL
.
x1 <- NULL for (i in 1:3) { x2 <- data.frame(a = 1:3, b = rnorm(3)) x1 <- safeColumnBind(x1, x2) # using cbind would result in an error: # x1 <- cbind(x1, x2) } x1#> a b a b a b #> 1 1 0.2585373 1 2.1268505 1 0.2494018 #> 2 2 -0.4417995 2 0.4248584 2 1.0728383 #> 3 3 0.5685999 3 -1.6842815 3 2.0393693