5.3.1.2 select_を使用したプログラミング例
OREdplyr
パッケージのselect_
関数の例。
例5-71 selectを使用したプログラミング
次の例では、select_
関数を使用して、iris data.frame
オブジェクトでore.push
関数を使用して作成されるIRIS ore.frame
オブジェクトの列を選択します。
IRIS <- ore.push(iris)
# Use ~, double quote, or quote function to specify the column to select
head(select_(IRIS, ~Petal.Length))
head(select_(IRIS, "Petal.Length"))
head(select_(IRIS, quote(-Petal.Length), quote(-Petal.Width)))
head(select_(IRIS, .dots = list(quote(-Petal.Length), quote(-Petal.Width))))
この例のリスト
R> IRIS <- ore.push(iris)
R> # Use ~, double quote, or quote function to specify the column to select
R> head(select_(IRIS, ~Petal.Length))
Petal.Length
1 1.4
2 1.4
3 1.3
4 1.5
5 1.4
6 1.7
R> head(select_(IRIS, "Petal.Length"))
Petal.Length
1 1.4
2 1.4
3 1.3
4 1.5
5 1.4
6 1.7
R> head(select_(IRIS, quote(-Petal.Length), quote(-Petal.Width)))
Sepal.Length Sepal.Width Species
1 5.1 3.5 setosa
2 4.9 3.0 setosa
3 4.7 3.2 setosa
4 4.6 3.1 setosa
5 5.0 3.6 setosa
6 5.4 3.9 setosa
R> head(select_(IRIS, .dots = list(quote(-Petal.Length), quote(-Petal.Width))))
Sepal.Length Sepal.Width Species
1 5.1 3.5 setosa
2 4.9 3.0 setosa
3 4.7 3.2 setosa
4 4.6 3.1 setosa
5 5.0 3.6 setosa
6 5.4 3.9 setosa
親トピック: データの選択および順序付け