loading...

Create a data frame (data.trame, base's data.frame, data.table or tibble's tbl_df)

dtx(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))

dtrm(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))

dtbl(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))

dtf(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))

dtt(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))

Arguments

...

A set of name-value pairs. The content of the data frame. See tibble() for more details on the way dynamic-dots are processed.

.name_repair

The way problematic column names are treated, see also tibble() for details.

Value

A data frame as a data.trame object for dtrm(), a tbl_df object for dtbl(), a data.frame for dtf() or a data.table for dtt().

Note

data.trame, data.table and tibble's tbl_df do no use row names. However, you can add a column named .rownames(by default), or the name that is in getOption("SciViews.dtx.rownames") and it will be automatically set as row names when the object is converted into a data.frame with as_dtf(). For dtf(), just create a column of this name and it is directly used as row names for the resulting data.frame object.

Examples

dtrm1 <- dtrm(
  x = 1:5,
  y = rnorm(5),
  f = letters[1:5],
  l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtrm1)
#> [1] "data.trame" "data.frame"

dtbl1 <- dtbl(
  x = 1:5,
  y = rnorm(5),
  f = letters[1:5],
  l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtbl1)
#> [1] "tbl_df"     "tbl"        "data.frame"

dtf1 <- dtf(
  x = 1:5,
  y = rnorm(5),
  f = letters[1:5],
  l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtf1)
#> [1] "data.frame"

dtt1 <- dtt(
  x = 1:5,
  y = rnorm(5),
  f = letters[1:5],
  l = sample(c(TRUE, FALSE), 5, replace = TRUE))
class(dtt1)
#> [1] "data.table" "data.frame"

# Using dtx(), one construct the preferred data frame object
# (a data.trame by default, can be changed with options(SciViews.as_dtx = ...))
dtx1 <- dtx(
  x = 1:5,
  y = rnorm(5),
  f = letters[1:5],
  l = sample(c(TRUE, FALSE), 5, replace = TRUE))
class(dtx1) # data.trame by default
#> [1] "data.trame" "data.frame"

# Use dtx_rows() to easily create a data frame:
dtx2 <- dtx_rows(
  ~x, ~y, ~f,
   1,  3, 'a',
   2,  4, 'b'
)
dtx2
#> # A data.trame: [2 × 3]
#>       x     y f    
#>   <dbl> <dbl> <chr>
#> 1     1     3 a    
#> 2     2     4 b    
class(dtx2)
#> [1] "data.trame" "data.frame"

# This is how you specify row names for dtf (data.frame)
dtf(x = 1:3, y = 4:6, .rownames = letters[1:3])
#>   x y
#> a 1 4
#> b 2 5
#> c 3 6