R/DefOps.R
, R/RowsColumns.R
, R/relops.R
unpivot_to_blocks.Rd
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 ) # S3 method for default unpivot_to_blocks( data, nameForNewKeyColumn, nameForNewValueColumn, columnsToTakeFrom, ..., nameForNewClassColumn = NULL, checkNames = TRUE, checkKeys = FALSE, strict = FALSE, allow_rqdatatable = FALSE ) # S3 method for 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.
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(.)#> model_name meas val #> 1 m1 AUC 0.6 #> 2 m1 R2 0.2d <- 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))#> mk_td("d", c( #> "AUC", #> "R2")) %.>% #> non_sql_node(., unpivot_to_blocks(., nameForNewKeyColumn="meas , nameForNewValueColumn="val"))if(requireNamespace("rqdatatable", quietly = TRUE)) { library("rqdatatable") d %.>% ops %.>% print(.) }#> meas val #> 1 AUC 0.6 #> 2 R2 0.2if(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) }#> meas val #> 1 AUC 0.6 #> 2 R2 0.2