4.3.1.1 Examples of Selecting Columns
Examples of the select
and rename
functions of the OREdplyr
package.
Example 4-70 Selecting Columns
The following examples select columns from the IRIS ore.frame
object that is created by using the ore.push
function on the iris data.frame
objects.
IRIS <- ore.push(iris)
# Select the specified column
names(select(IRIS, Petal.Length))
names(select(IRIS, petal_length = Petal.Length))
# Drop the specified column
names(select(IRIS, -Petal.Length))
# rename() keeps all variables
names(rename(IRIS, petal_length = Petal.Length))
Listing for This Example
R> IRIS <- ore.push(iris)
R> # Select the specified column
R> names(select(IRIS, Petal.Length))
[1] "Petal.Length"
R> names(select(IRIS, petal_length = Petal.Length))
[1] "petal_length"
R>
R> # Drop the specified column
R> names(select(IRIS, -Petal.Length))
[1] "Sepal.Length" "Sepal.Width" "Petal.Width" "Species"
R>
R> # rename() keeps all variables
R> names(rename(IRIS, petal_length = Petal.Length))
[1] "Sepal.Length" "Sepal.Width" "petal_length" "Petal.Width" "Species"
Parent topic: Select and Order Data