df_append: Appending Columns to Data Frames

Description Usage Arguments Value Examples

View source: R/utils.R

Description

This function performs on data.frame objects a similar operation as append does on list objects. That is it enables prepending/inserting/appending columns at specific positions.

Usage

1
2
3
4
5
6
7
df_append(
  x,
  ...,
  after = length(x),
  names = NULL,
  stringsAsFactors = getOption("stringsAsFactors", FALSE)
)

Arguments

x

a data.frame object

...

variables to be appended to x.

after

index or column name after which the new variables should be inserted. Default is to append the columns at the end of the data.frame.

names

optional names for the newly inserted columns.

stringsAsFactors

logical that indicates if the newly inserted string variables should be converted to factors.

Value

a data.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- data.frame(a = 1:4, b = letters[1:4])
# append at the end
df_append(x, c = runif(4))

# append at the beginning
df_append(x, c = runif(4), after = 0L)

# append after first column
df_append(x, c = runif(4), after = 1L)
df_append(x, c = runif(4), after = 'a')

renozao/xbioc documentation built on Sept. 3, 2020, 1:13 a.m.