data.table.rc: data.table Creation, [R,C] defined

Description Usage Arguments Details Value Examples

Description

data.table.rc creates a data.frame using the [R,C] format like 'matrix' (arguments: 'nrow', 'ncol').

Usage

1
2
data.table.rc(values, nrow, ncol = length(values),
  column_names = names(values))

Arguments

values

Type: list or vector to repeat. The values inside the data.table.

nrow

Type: numeric. The number of rows in the data.table to create.

ncol

Type: numeric. The number of columns in the data.table to create. Defaults to length(values).

column_names

Type: character. The names of the columns in the data.table to create. Defaults to names(values).

Details

Please see vignette for demos: vignette("data.table.rc", package = "Laurae2") or help_me("data.table.rc").

Value

A data.table with [nrow, ncol] strucure specified, along with column names (defaults to V1, V2, V3...)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Create default named [5, 5] data.frame
data.table.rc(0, nrow = 5, ncol = 5)

# Create named [5, 5] data.frame
data.table.rc(0, nrow = 5, ncol = 5,
              column_names = c("car", "minicooper", "truck", "porsche", "speedo"))

# Create named [5, 5] data.frame with values
data.table.rc(list(1:5,
                   c(TRUE, FALSE, TRUE, FALSE, TRUE),
                   5:1,
                   c("has", "not", "has", "not", "has"),
                   c(150L, 200L, 250L, 300L, 350L)),
              nrow = 5, ncol = 5)

# Create named [5, 5] data.frame with named values
data.table.rc(list(1:5,
                   c(TRUE, FALSE, TRUE, FALSE, TRUE),
                   5:1,
                   c("has", "not", "has", "not", "has"),
                   c(150L, 200L, 250L, 300L, 350L)),
              nrow = 5, ncol = 5,
              column_names = c("car", "minicooper", "truck", "porsche", "speedo"))

# Create named [5, 5] data.frame with values
data.table.rc(list(car = 1:5,
                   minicooper = c(TRUE, FALSE, TRUE, FALSE, TRUE),
                   truck = 5:1,
                   porsche = c("has", "not", "has", "not", "has"),
                   speedo = c(150L, 200L, 250L, 300L, 350L)),
              nrow = 5, ncol = 5)

Laurae2/Laurae2 documentation built on May 18, 2019, 11:27 p.m.