Description Usage Arguments Details Examples
View source: R/computeAggregates.R
Compute aggregates using SQL SELECT...GROUP BY in Aster. Aggregates may be any
valid SQL expressions (including SQL WINDOW functions) in context of group
columns (parameter by). Neither SQL ORDER BY nor LIMIT clauses
are supported (use computeBarchart when they are required).
1 2 |
channel |
connection object as returned by |
tableName |
table name |
aggregates |
vector of SQL aggregates to compute. Aggregates may have
optional aliases like in |
by |
character vecotr of column names and/or expressions on which grouping is performed
(with SQL |
where |
specifies criteria to satisfy by the table rows before applying
computation. The creteria are expressed in the form of SQL predicates (inside
|
... |
additional arguments to be passed to |
test |
logical: if TRUE show what would be done, only (similar to parameter |
No columns returned as character and not excluded by as.is are
converted to factors by default, i.e. stringsAsFactors = FALSE when calling
sqlQuery if not specified when calling this function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | if(interactive()){
# initialize connection to Lahman baseball database in Aster
conn = odbcDriverConnect(connection="driver={Aster ODBC Driver};
server=<dbhost>;port=2406;database=<dbname>;uid=<user>;pwd=<pw>")
# compute average team rank and attendance by decade
data = computeAggregates(channel = conn, tableName = "teams_enh",
by = c("name || ', ' || park teamname", "lgid", "teamid", "decadeid"),
aggregates = c("min(name) name", "min(park) park", "avg(rank) rank",
"avg(attendance) attendance"))
# compute total strike-outs for each team in decades starting with 1980
# and also percent (share) of team strikeouts within a decade
data = computeAggregates(channel = conn, "pitching_enh",
by = c("teamid", "decadeid"),
aggregates = c("sum(so) so",
"sum(so)/(sum(sum(so)) over (partition by decadeid)) percent"),
where = "decadeid >= 1980")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.