These methods handle data.trame objects correctly, so that they remain internally consistent with data.tables.
# S3 method for class 'data.trame'
head(x, n = 6L, ...)
# S3 method for class 'data.trame'
tail(x, n = 6L, ...)
# S3 method for class 'data.trame'
names(x) <- value
set_names()
let_names(x, value)
# S3 method for class 'data.trame'
row.names(x) <- value
set_row_names(x, value)
let_row_names(x, value)
# S3 method for class 'data.trame'
edit(name, ...)
# S3 method for class 'data.trame'
cbind(
x,
...,
keep.rownames = FALSE,
check.names = FALSE,
key = NULL,
stringsAsFactors = FALSE
)
# S3 method for class 'data.trame'
rbind(
x,
...,
use.names = TRUE,
fill = FALSE,
idcol = NULL,
ignore.attr = FALSE
)
A data.trame object.
The number of rows to keep.
Further parameters (not used yet).
The value passed to the method.
The name of the data.trame to edit.
If TRUE
, the row names are kept as a column
If TRUE
, the names of the columns are checked
The key to set on the resulting data.trame. If NULL
, no key is set.
If TRUE
, character columns are converted to factors.
If TRUE
, the names of the columns are matched. If FALSE
,
match is done by position. if "check"
, warn if names do not match.
If TRUE
, fill missing columns with NA
. By default FALSE
.
Create a column with ids showing where the data come from. With
TRUE
, the column is named id
. With idcol = "col_name"
, it has that
name.
If TRUE
, ignore attributes when binding.
head()
and tail()
return truncated data.trame objects (n first
or last rows). names(dtrm) <- value
and set_names()
both set names
(colnames). let_names()
change names by reference.
row.names(dtrm) <- value
and set_row_names()
both set the
row names of a data.trame. However, only the second one keeps the selfref
pointer integrity. let_row_names()
is a faster version, but it changes the
row names by reference. With all let_xxx()
functions, you need to take
extra care to avoid unexpected side effects, see examples. cbind()
combines
data.trames by columns, rbind()
combines them by rows.
dtrm <- data.trame(
a = 1:10,
b = letters[1:10],
c = factor(LETTERS[1:10]), .key = c('a', 'b')
)
head(dtrm)
#> # A data.trame: [6 × 3]
#> # Key: a, b
#> a b c
#> <int> <chr> <fct>
#> 1 1 a A
#> 2 2 b B
#> 3 3 c C
#> 4 4 d D
#> 5 5 e E
#> 6 6 f F
tail(dtrm, n = 3L)
#> # A data.trame: [3 × 3]
#> # Key: a, b
#> a b c
#> <int> <chr> <fct>
#> 1 8 h H
#> 2 9 i I
#> 3 10 j J
cbind(dtrm, dtrm)
#> # A data.trame: [10 × 6]
#> a b c a b c
#> <int> <chr> <fct> <int> <chr> <fct>
#> 1 1 a A 1 a A
#> 2 2 b B 2 b B
#> 3 3 c C 3 c C
#> 4 4 d D 4 d D
#> 5 5 e E 5 e E
#> 6 6 f F 6 f F
#> 7 7 g G 7 g G
#> 8 8 h H 8 h H
#> 9 9 i I 9 i I
#> 10 10 j J 10 j J
rbind(dtrm, dtrm)
#> # A data.trame: [20 × 3]
#> a b c
#> <int> <chr> <fct>
#> 1 1 a A
#> 2 2 b B
#> 3 3 c C
#> 4 4 d D
#> 5 5 e E
#> 6 6 f F
#> 7 7 g G
#> 8 8 h H
#> 9 9 i I
#> 10 10 j J
#> 11 1 a A
#> 12 2 b B
#> 13 3 c C
#> 14 4 d D
#> 15 5 e E
#> 16 6 f F
#> 17 7 g G
#> 18 8 h H
#> 19 9 i I
#> 20 10 j J
dtrm2 <- set_row_names(dtrm, paste("row", letters[1:10]))
dtrm2
#> # A data.trame: [10 × 3]
#> # Key: a, b
#> a b c
#> * <int> <chr> <fct>
#> row a 1 a A
#> row b 2 b B
#> row c 3 c C
#> row d 4 d D
#> row e 5 e E
#> row f 6 f F
#> row g 7 g G
#> row h 8 h H
#> row i 9 i I
#> row j 10 j J
dtrm # Not changed
#> # A data.trame: [10 × 3]
#> # Key: a, b
#> a b c
#> <int> <chr> <fct>
#> 1 1 a A
#> 2 2 b B
#> 3 3 c C
#> 4 4 d D
#> 5 5 e E
#> 6 6 f F
#> 7 7 g G
#> 8 8 h H
#> 9 9 i I
#> 10 10 j J
# Take care with let_xxx() functions: it propagates changes to other
# data.trames if you did not used copy()!
dtrm2 <- dtrm
dtrm3 <- data.table::copy(dtrm)
let_row_names(dtrm2, paste("row", letters[11:20]))
dtrm2 # OK
#> # A data.trame: [10 × 3]
#> # Key: a, b
#> a b c
#> * <int> <chr> <fct>
#> row k 1 a A
#> row l 2 b B
#> row m 3 c C
#> row n 4 d D
#> row o 5 e E
#> row p 6 f F
#> row q 7 g G
#> row r 8 h H
#> row s 9 i I
#> row t 10 j J
dtrm # Also changed!
#> # A data.trame: [10 × 3]
#> # Key: a, b
#> a b c
#> * <int> <chr> <fct>
#> row k 1 a A
#> row l 2 b B
#> row m 3 c C
#> row n 4 d D
#> row o 5 e E
#> row p 6 f F
#> row q 7 g G
#> row r 8 h H
#> row s 9 i I
#> row t 10 j J
dtrm3 # Not changed, because created using copy()
#> # A data.trame: [10 × 3]
#> # Key: a, b
#> a b c
#> <int> <chr> <fct>
#> 1 1 a A
#> 2 2 b B
#> 3 3 c C
#> 4 4 d D
#> 5 5 e E
#> 6 6 f F
#> 7 7 g G
#> 8 8 h H
#> 9 9 i I
#> 10 10 j J