Append {DescTools} | R Documentation |
Append elements to a number of various objects as vectors, matrices, data.frames and lists. In a matrix either rows or columns can be inserted at any position. In data frames any vectors can be inserted. values
will be recycled to the necessary length.
Append(x, values, after = NULL, ...)
## S3 method for class 'matrix'
Append(x, values, after = NULL, rows = FALSE, names = NULL, ...)
## S3 method for class 'data.frame'
Append(x, values, after = NULL, rows = FALSE, names = NULL, ...)
## Default S3 method:
Append(x, values, after = NULL, ...)
x |
object for the elements to be inserted |
values |
the elements to be inserted |
after |
a subscript, after which the values are to be appended. If it's missing the values will be appended after the last element (or column/row). |
rows |
logical, defining if vector should be added as row or as column. Default is column ( |
names |
the dimension names for the inserted elements(s) |
... |
further arguments (not used here) |
The vector x
will be recycled to a length of the next multiple of the number of rows (or columns) of the matrix m
and will be inserted such that the first inserted row (column) has the index i
. If the dimnames are given, they will be used no matter if the matrix m has already dimnames defined or not.
An object containing the values in x with the elements of values appended after the specified element of x.
Andri Signorell <andri@signorell.net>
Append(1:5, 0:1, after = 3) # the same as append
# Insert columns and rows
x <- matrix(runif(25), 5)
Append(x, values=1:10, after=2, names = c("X","Y"))
Append(x, values=1:10, after=2)
Append(x, values=1:10, after=2, names = c("X","Y"))
Append(x, values=1:10, after=2)
# append to a data.frame
d.frm <- data.frame("id" = c(1,2,3),
"code" = c("AAA", "BBB", "CCC"),
"val" = c(111, 222, 333))
z <- c(10, 20, 30)
Append(d.frm, z, after=2, names="ZZZ")