Description Usage Arguments Details Value Examples
TApply
returns a transformed object according to the transformation rules.
1 2 3 4 5 6 7 |
x |
Object of class StQ or data.table with data to transform |
Tr |
Object of class StQT with the transformation we are going to apply. |
There are three kinds of transformation rules: internal functions, row insertion and column insertion.
Internal functionsFunDelRow, FunDelVar and FunAutoLink so far. The first one deletes rows in domain. The second one deletes the variables specified in the output. The third one copies the input variables from the table linking according to the expression in domain.
Row insertionRow are inserted. This kind of rule is applied when there exists an assignment in the output. Unassigned variables are calculated according output = fun(input). Any variable included in by is copied into the new rows.
Column insertionRows are calculated according output = fun (input)
Parameter domain specifies the subset of the dataset where we are going to do the calculation. Parameter by sets the variables where we are applying the rule by. Parameter order orders the table, previously to apply the transformation. Parameter key (irrelevant for data.table) sets which of the variables are qualifiers.
StQ or data.table respectively with transformed data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | require(data.table)
dt <- data.table(Region = c("1","2","3"), GDP = c(1.38,0.94,1.23))
dt
T1 <- NewStQT(data.frame(
output = "Region='Total',GDP",
fun = "sum",
input = "GDP",
stringsAsFactors = FALSE))
TApply(dt,T1)
require(StQ)
data(ExampleStQ)
rules <- data.frame(domain = c('','Turnover > 0'),
output = c('AggTurnover','LogTurnover'),
fun = c('sum','log'),
input = c('Turnover','Turnover'),
by = c('NACE09',''),
key = c('NACE09',''),
stringsAsFactors = FALSE)
T2 <- NewStQT(rules)
(ExampleStQ2 <- TApply(ExampleStQ,T2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.