smartbind: Efficient rbind of data frames, even if the column names...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/smartbind.R

Description

Efficient rbind of data frames, even if the column names don't match

Usage

1
smartbind(..., fill=NA, sep=':', verbose=FALSE)

Arguments

...

Data frames to combine

fill

Value to use when 'filling' missing columns. Defaults to NA.

sep

Character string used to separate column names when pasting them together.

verbose

Logical flag indicating whether to display processing messages. Defaults to FALSE.

Value

The returned data frame will contain:

columns

all columns present in any provided data frame

rows

a set of rows from each provided data frame, with values in columns not present in the given data frame filled with missing (NA) values.

The data type of columns will be preserved, as long as all data frames with a given column name agree on the data type of that column. If the data frames disagree, the column will be converted into a character strings. The user will need to coerce such character columns into an appropriate type.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

rbind, cbind

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  df1 <- data.frame(A=1:10, B=LETTERS[1:10], C=rnorm(10) )
  df2 <- data.frame(A=11:20, D=rnorm(10), E=letters[1:10] )

  # rbind would fail
## Not run: 
  rbind(df1, df2)
  # Error in match.names(clabs, names(xi)) : names do not match previous
  # names:
  #	D, E

## End(Not run)
  # but smartbind combines them, appropriately creating NA entries
  smartbind(df1, df2)

  # specify fill=0 to put 0 into the missing row entries
  smartbind(df1, df2, fill=0)

gtools documentation built on May 30, 2017, 1:58 a.m.

Search within the gtools package
Search all R packages, documentation and source code