r<raven table> 3 rows ⨉ 3 columns age sbp sex double double factor 1 40 120 f 2 52 140 m 3 61 155 f
The examples use one raven:
<raven table> 3 rows ⨉ 3 columns age sbp sex double double factor 1 40 120 f 2 52 140 m 3 61 155 f
r8filter() keeps the rows where a rule is true, and r8select() gives columns by name or by position:
<raven table> 1 row ⨉ 3 columns age sbp sex double double factor 1 61 155 f
<raven table> 3 rows ⨉ 2 columns sex age factor double 1 f 40 2 m 52 3 f 61
x[rule, columns] is the same in one call. Every index is R’s, as it is of a data frame, and a rule is an index of rows:
<raven table> 2 rows ⨉ 2 columns sex age factor double 1 m 52 2 f 61
<raven table> 2 rows ⨉ 1 column sex factor 1 m 2 f
r8sort() orders the rows by columns, the first foremost, and descending names those that descend. Missing cells come last, strings are in the order of their code points in every locale, and factors in that of their levels:
<raven table> 3 rows ⨉ 3 columns age sbp sex double double factor 1 61 155 f 2 40 120 f 3 52 140 m
A name in rule() is a column, and val() is the value of an R expression. What a call means is in the call alone, whatever the table and the session hold:
<raven table> 1 row ⨉ 3 columns age sbp sex double double factor 1 61 155 f
Without rule(), a name is R’s variable. Where R has none, the error writes the rule:
Error:
! R has no variable `age`, which is a column of the table; a condition on columns is a rule: rule(age > 45).
A rule is declared on its own, filters every table that has the columns it names, and checks the rows of a type (Declaring a table type). !, &, and | make a rule of others:
<raven table> 1 row ⨉ 3 columns age sbp sex double double factor 1 40 120 f
A rule is checked against the columns and their types before a row is read:
Error:
! The rule does not fit the table: `>=` compares two numbers, two dates, or two date-times, found a string and a number.
A string compared with a date or a date-time is one, rule(day >= "2020-01-31"). The cell of a factor is its label. Backticks quote a name that is not a name of R, rule(`Age (years)` > 40).
A row is kept where the rule is true. Where a cell is missing, a comparison is missing, so that the row is in neither part:
<raven table> 1 row ⨉ 1 column a double 1 3
<raven table> 1 row ⨉ 1 column a double 1 1
<raven table> 2 rows ⨉ 1 column a double 1 NA 1 NA 2 3
NaN is missing too. A logical vector of R with a missing value is refused as an index.
mean(x), sum(x), min(x), and max(x) in a filter read the whole column, and are missing where one of its cells is. pmin(a, b) and pmax(a, b) are the least and the greatest cell of the row:
R CMD check takes a bare name in a function for a variable that nothing binds. A function of a package quotes the condition, which gives the same rule: rule(quote(age > val(cutoff))).
A position past the end and a column that the table does not have are errors: