プライマリ・コンテンツに移動
Oracle® R Enterpriseユーザーズ・ガイド
リリース1.5
E67082-02
目次へ移動
目次
索引へ移動
索引

前
前へ
次
次へ

3.1.2.2 行によるデータの選択

例3-2では、順序付けられているore.frameオブジェクトから行を選択します。この例では最初に、順序付けられたore.frameオブジェクトの作成に使用するために、irisdata.frameオブジェクトに列を追加します。データベース表IRIS_TABLEが存在する場合は、ore.drop関数を呼び出して削除します。次に、irisdata.frameから、対応するプロキシore.frameオブジェクトのIRIS_TABLEとともに、データベース表を作成します。例では、ore.exec関数を呼び出して、RID列をデータベース表の主キーにするためのSQL文を実行します。次にore.sync関数を呼び出して、IRIS_TABLEore.frameオブジェクトをこの表と同期化させ、プロキシore.frameオブジェクトの最初の3行を表示します。

例3-2では次に、IRIS_TABLEから行番号で51行を選択し、それを使用して順序付けられたore.frameオブジェクトのiris_selrowsを作成します。この例では、iris_selrowsの最初の6行を表示します。その後、行名で3行を選択して結果を表示します。

例3-2 行によるデータの選択

# 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"),]
例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