5.1.2.2 行によるデータの選択
この例では、順序付けられたore.frame
オブジェクトから行を選択します。
例5-2 行によるデータの選択
この例では最初に、順序付けられたore.frame
オブジェクトの作成に使用するために、iris
のdata.frame
オブジェクトに列を追加します。データベース表IRIS_TABLEが存在する場合は、ore.drop
関数を実行して削除します。次に、iris
のdata.frame
から、対応するプロキシore.frame
オブジェクトのIRIS_TABLE
とともに、データベース表を作成します。この例では、ore.exec
関数を実行して、RID列をデータベース表の主キーにするためのSQL文を実行します。次にore.sync
関数を実行して、IRIS_TABLE
のore.frame
オブジェクトをこの表と同期化させ、プロキシore.frame
オブジェクトの最初の3行を表示します。
例では次に、IRIS_TABLE
から行番号で51行を選択し、それを使用して順序付けられたore.frame
オブジェクトのiris_selrows
を作成します。この例では、iris_selrows
の最初の6行を表示します。その後、行名で3行を選択して結果を表示します。
# 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"),]この例のリスト
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
親トピック: データの選択