Map data records from block records (which each record may be more than one row) to row records (where each record is a single row).
blocks_to_rowrecs( tallTable, keyColumns, controlTable, ..., columnsToCopy = NULL, checkNames = TRUE, checkKeys = TRUE, strict = FALSE, controlTableKeys = colnames(controlTable)[[1]], tmp_name_source = wrapr::mk_tmp_name_source("bltrr"), temporary = TRUE, allow_rqdatatable = FALSE ) # S3 method for default blocks_to_rowrecs( tallTable, keyColumns, controlTable, ..., columnsToCopy = NULL, checkNames = TRUE, checkKeys = FALSE, strict = FALSE, controlTableKeys = colnames(controlTable)[[1]], tmp_name_source = wrapr::mk_tmp_name_source("btrd"), temporary = TRUE, allow_rqdatatable = FALSE ) # S3 method for relop blocks_to_rowrecs( tallTable, keyColumns, controlTable, ..., columnsToCopy = NULL, checkNames = TRUE, checkKeys = FALSE, strict = FALSE, controlTableKeys = colnames(controlTable)[[1]], tmp_name_source = wrapr::mk_tmp_name_source("bltrr"), temporary = TRUE, allow_rqdatatable = FALSE )Arguments tallTable
data.frame containing data to be mapped (in-memory data.frame).
keyColumnscharacter vector of column defining row groups
controlTabletable specifying mapping (local data frame)
...force later arguments to be by name.
columnsToCopycharacter, extra columns to copy.
checkNameslogical, if TRUE check names.
checkKeyslogical, if TRUE check keyColumns uniquely identify blocks (required).
strictlogical, if TRUE check control table name forms
controlTableKeyscharacter, which column names of the control table are considered to be keys.
tmp_name_sourcea tempNameGenerator from cdata::mk_tmp_name_source()
temporarylogical, if TRUE use temporary tables
allow_rqdatatablelogical, if TRUE allow rqdatatable shortcutting on simple conversions.
Valuewide table built by mapping key-grouped tallTable rows to one row per group
DetailsThe controlTable defines the names of each data element in the two notations: the notation of the tall table (which is row oriented) and the notation of the wide table (which is column oriented). controlTable[ , 1] (the group label) cross colnames(controlTable) (the column labels) are names of data cells in the long form. controlTable[ , 2:ncol(controlTable)] (column labels) are names of data cells in the wide form. To get behavior similar to tidyr::gather/spread one builds the control table by running an appropriate query over the data.
Some discussion and examples can be found here: https://winvector.github.io/FluidData/FluidData.html and here https://github.com/WinVector/cdata.
See alsobuild_pivot_control
, rowrecs_to_blocks
# pivot example d <- data.frame(meas
= c('AUC',
'R2'), val
= c(0.6,
0.2)) cT <- build_pivot_control(d, columnToTakeKeysFrom
= 'meas', columnToTakeValuesFrom
= 'val') blocks_to_rowrecs(d, keyColumns
= NULL, controlTable
= cT)#> AUC R2 #> 1 0.6 0.2
d <- data.frame(meas
= c('AUC',
'R2'), val
= c(0.6,
0.2)) cT <- build_pivot_control( d, columnToTakeKeysFrom
= 'meas', columnToTakeValuesFrom
= 'val') ops <- rquery::local_td(d) %.>% blocks_to_rowrecs(., keyColumns
= NULL, controlTable
= cT) cat(format(ops))#> mk_td("d", c( #> "meas", #> "val")) %.>% #> non_sql_node(., CREATE TEMPORARY TABLE "OUT" AS SELECT MAX( CASE WHEN CAST(a."meas" AS VARCHAR) = 'AUC' THEN a."val" ELSE NULL END ) "AUC", MAX( CASE WHEN CAST(a."meas" AS VARCHAR) = 'R2' THEN a."val" ELSE NULL END ) "R2" FROM "IN" a )
#> Loading required package: rquery
#> AUC R2 #> 1 0.6 0.2
#> AUC R2 #> 1 0.6 0.2
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4