unpivot_to_blocks | R Documentation |
Map a data records from row records (records that are exactly single rows) to block records (records that may be more than one row). All columns not named in columnsToTakeFrom are copied to each record row in the result.
unpivot_to_blocks(
data,
nameForNewKeyColumn,
nameForNewValueColumn,
columnsToTakeFrom,
...,
nameForNewClassColumn = NULL,
checkNames = TRUE,
checkKeys = FALSE,
strict = FALSE,
tmp_name_source = wrapr::mk_tmp_name_source("upb"),
temporary = TRUE,
allow_rqdatatable = FALSE
)
layout_to_blocks(
data,
nameForNewKeyColumn,
nameForNewValueColumn,
columnsToTakeFrom,
...,
nameForNewClassColumn = NULL,
checkNames = TRUE,
checkKeys = FALSE,
strict = FALSE,
tmp_name_source = wrapr::mk_tmp_name_source("upb"),
temporary = TRUE,
allow_rqdatatable = FALSE
)
pivot_to_blocks(
data,
nameForNewKeyColumn,
nameForNewValueColumn,
columnsToTakeFrom,
...,
nameForNewClassColumn = NULL,
checkNames = TRUE,
checkKeys = FALSE,
strict = FALSE,
tmp_name_source = wrapr::mk_tmp_name_source("upb"),
temporary = TRUE,
allow_rqdatatable = FALSE
)
## Default S3 method:
unpivot_to_blocks(
data,
nameForNewKeyColumn,
nameForNewValueColumn,
columnsToTakeFrom,
...,
nameForNewClassColumn = NULL,
checkNames = TRUE,
checkKeys = FALSE,
strict = FALSE,
allow_rqdatatable = FALSE
)
## S3 method for class 'relop'
unpivot_to_blocks(
data,
nameForNewKeyColumn,
nameForNewValueColumn,
columnsToTakeFrom,
...,
checkNames = TRUE,
checkKeys = FALSE,
strict = FALSE,
nameForNewClassColumn = NULL,
tmp_name_source = wrapr::mk_tmp_name_source("upb"),
temporary = TRUE,
allow_rqdatatable = FALSE
)
data |
data.frame to work with. |
nameForNewKeyColumn |
character name of column to write new keys in. |
nameForNewValueColumn |
character name of column to write new values in. |
columnsToTakeFrom |
character array names of columns to take values from. |
... |
force later arguments to bind by name. |
nameForNewClassColumn |
optional name to land original cell classes to. |
checkNames |
logical, if TRUE check names. |
checkKeys |
logical, if TRUE check columnsToCopy form row keys (not a requirement, unless you want to be able to invert the operation). |
strict |
logical, if TRUE check control table name forms. |
tmp_name_source |
a tempNameGenerator from cdata::mk_tmp_name_source() |
temporary |
logical, if TRUE make result temporary. |
allow_rqdatatable |
logical, if TRUE allow rqdatatable shortcutting on simple conversions. |
new data.frame with values moved to rows.
pivot_to_rowrecs
, rowrecs_to_blocks
d <- data.frame(model_name = "m1", AUC = 0.6, R2 = 0.2)
unpivot_to_blocks(d,
nameForNewKeyColumn= 'meas',
nameForNewValueColumn= 'val',
columnsToTakeFrom= c('AUC', 'R2')) %.>%
print(.)
d <- data.frame(AUC= 0.6, R2= 0.2)
ops <- rquery::local_td(d) %.>%
unpivot_to_blocks(
.,
nameForNewKeyColumn= 'meas',
nameForNewValueColumn= 'val',
columnsToTakeFrom= c('AUC', 'R2'))
cat(format(ops))
if(requireNamespace("rqdatatable", quietly = TRUE)) {
library("rqdatatable")
d %.>%
ops %.>%
print(.)
}
if(requireNamespace("RSQLite", quietly = TRUE)) {
db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(db,
'd',
d,
overwrite = TRUE,
temporary = TRUE)
db %.>%
ops %.>%
print(.)
DBI::dbDisconnect(db)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.