if (FALSE) {
#————————————————————————————————————————————————————————————————————————————
# Select Single Variables
# Example 1: Select 'Sepal.Length' and 'Petal.Width'
df.subset(iris, Sepal.Length, Petal.Width)
#————————————————————————————————————————————————————————————————————————————
# Select Rows
# Example 2a: Select all variables, select rows with 'Species' equal 'setosa'
df.subset(iris, subset = Species == "setosa")
# Example 2b: Select all variables, select rows with 'Petal.Length' smaller 1.2
df.subset(iris, subset = Petal.Length < 1.2)
# Example 2C: Select 'Sepal.Length' and 'Petal.Width',
# select rows with 'Species' equal 'setosa'
df.subset(iris, Sepal.Length, Petal.Width, subset = Species == "setosa")
#————————————————————————————————————————————————————————————————————————————
# Select Variables Matching a Prefix using the + Operator
# Example 3: Select variables with prefix 'Petal'
df.subset(iris, +Petal)
#————————————————————————————————————————————————————————————————————————————
# Select Variables Matching a Suffix using the - Operator
# Example 4: Select variables with suffix 'Width'
df.subset(iris, -Width)
#————————————————————————————————————————————————————————————————————————————
# Select Variables Containing a Word using the ~ Operator
# Example 5: Select variables containing 'al'
df.subset(iris, ~al)
#————————————————————————————————————————————————————————————————————————————
# Select Consecutive Variables using the : Operator
# Example 6: Select all variables from 'Sepal.Width' to 'Petal.Width'
df.subset(iris, Sepal.Width:Petal.Width)
#————————————————————————————————————————————————————————————————————————————
# Select Numbered Variables using the :: Operator
# Example 7: Select all variables from 'x1' to 'x3' and 'y1' to 'y3'
df.subset(anscombe, x1::x3, y1::y3)
#————————————————————————————————————————————————————————————————————————————
# Drop Variables using the ! Operator
# Example 8a: Select all variables except 'Sepal.Width'
df.subset(iris, !Sepal.Width)
# Example 8b: Select all variables except variables with prefix 'Petal'
df.subset(iris, !+Petal)
# Example 8c: Select all variables except variables with suffix 'Width'
df.subset(iris, !-Width)
# Example 8d: Select all variables except 'Sepal.Width' to 'Petal.Width'
df.subset(iris, !Sepal.Width:Petal.Width)
#————————————————————————————————————————————————————————————————————————————
# Combine +, -, !, and : Operators
# Example 9: Select variables with prefix 'x' and suffix '3', but exclude
# variables from 'x2' to 'x3'
df.subset(anscombe, +x, -3, !x2:x3)
}
Run the code above in your browser using DataLab