addrows: Add rows to a data.frame

Description Usage Arguments Details Examples

View source: R/addrows.R

Description

An "rbind for data.frames", sort of.

Usage

1
addrows(dtf, nrw, top = FALSE)

Arguments

dtf

data.frame; original data.frame

nrw

data.frame; the new row(s) to be added

top

logical; should the new rows be added to the top or the bottom (default)?

Details

Can only bind two objects at a time, but will bind data.frames with non-matching column names and -classes. In such cases the original data.frame will serve as template.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
dtf <- data.frame(A=letters[1:5], 
                  B=1:5, 
                  C=as.factor(5:1), 
                  D=as.Date(0:4, origin="2000-01-01"),
                  stringsAsFactors=FALSE)

nrw <- data.frame(A=letters[1:5], 
                  B=4:8, 
                  C=5:1, 
                  D=as.Date(5:1, origin="1990-01-01"),
                  stringsAsFactors=FALSE)
str(dtf)

dtf.a <- addrows(dtf, nrw, top=FALSE)
str(dtf.a)

# adding a single row with little concern for data types and column names
b <- type.convert(beaver1[80:90,])
b$activ <- as.logical(b$activ)

addrows(b, data.frame(350, 1200, 37.02, 1))

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.