Example 3-2 selects rows from an ordered ore.frame
object. The example first adds a column to the iris
data.frame
object for use in creating an ordered ore.frame
object. It invokes the ore.drop
function to delete the database table IRIS_TABLE, if it exists. It then creates a database table, with the corresponding proxy ore.frame
object IRIS_TABLE
, from the iris
data.frame
. The example invokes the ore.exec
function to execute a SQL statement that makes the RID column the primary key of the database table. It then invokes the ore.sync
function to synchronize the IRIS_TABLE
ore.frame
object with the table and displays the first three rows of the proxy ore.frame
object.
Example 3-2 next selects 51 rows from IRIS_TABLE
by row number and creates the ordered ore.frame
object iris_selrows
with them. It displays the first six rows of iris_selrows
. It then selects 3 rows by row name and displays the result.
Example 3-2 Selecting Data by Row
# Add a column to the iris data set to use as row identifiers. iris$RID <- as.integer(1:nrow(iris) + 100) ore.drop(table = 'IRIS_TABLE') ore.create(iris, table = 'IRIS_TABLE') ore.exec("alter table IRIS_TABLE add constraint IRIS_TABLE primary key (\"RID\")") ore.sync(table = "IRIS_TABLE") head(IRIS_TABLE, 3) # Select rows by row number. iris_selrows <- IRIS_TABLE[50:100,] head(iris_selrows) # Select rows by row name. IRIS_TABLE[c("101", "151", "201"),]Listing for Example 3-2
R> # Add a column to the iris data set to use as row identifiers. R> iris$RID <- as.integer(1:nrow(iris) + 100) R> ore.drop(table = 'IRIS_TABLE') R> ore.create(iris, table = 'IRIS_TABLE') R> ore.exec("alter table IRIS_TABLE add constraint IRIS_TABLE + primary key (\"RID\")") R> ore.sync(table = "IRIS_TABLE") R> head(IRIS_TABLE, 3) Sepal.Length Sepal.Width Petal.Length Petal.Width Species RID 101 5.1 3.5 1.4 0.2 setosa 101 102 4.9 3.0 1.4 0.2 setosa 102 103 4.7 3.2 1.3 0.2 setosa 103 R> # Select rows by row number. R> iris_selrows <- IRIS_TABLE[50:100,] R> head(iris_selrows) Sepal.Length Sepal.Width Petal.Length Petal.Width Species RID 150 5.0 3.3 1.4 0.2 setosa 150 151 7.0 3.2 4.7 1.4 versicolor 151 152 6.4 3.2 4.5 1.5 versicolor 152 153 6.9 3.1 4.9 1.5 versicolor 153 154 5.5 2.3 4.0 1.3 versicolor 154 155 6.5 2.8 4.6 1.5 versicolor 155 R> # Select rows by row name. R> IRIS_TABLE[c("101", "151", "201"),] Sepal.Length Sepal.Width Petal.Length Petal.Width Species RID 101 5.1 3.5 1.4 0.2 setosa 101 151 7.0 3.2 4.7 1.4 versicolor 151 201 6.3 3.3 6.0 2.5 virginica 201