Skip to contents

If x1 is NULL x2 is returned otherwise cbind(x1, x2)

Usage

safeColumnBind(x1, x2)

Arguments

x1

first object to be passed to cbind

x2

second object to be passed to cbind

Value

result of cbind(x1, x2) or x2 if x1

is NULL.

Examples

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.9676737 1 -0.9369726 1 -2.1443322
#> 2 2  0.7924511 2  0.8613005 2  0.4847217
#> 3 3  1.8150308 3  0.6216399 3 -0.4472743