Description Usage Arguments Value Special functions See Also Examples
select()
keeps only the variables you mention; rename()
keeps all variables.
1 2 3 4 5 6 7 |
.data |
A tbl. All main verbs are S3 generics and provide methods
for |
... |
Comma separated list of unquoted expressions. You can treat variable names like they are positions. Use positive values to select variables; use negative values to drop variables. |
.dots |
Use |
An object of the same class as .data
.
Data frame row names are silently dropped. To preserve, convert to an explicit variable.
As well as using existing functions like :
and c
, there are
a number of special functions that only work inside select
To drop variables, use -
. You can rename variables with
named arguments.
Other single.table.verbs: arrange
,
filter
, mutate
,
slice
, summarise
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | iris <- tbl_df(iris) # so it prints a little nicer
select(iris, starts_with("Petal"))
select(iris, ends_with("Width"))
select(iris, contains("etal"))
select(iris, matches(".t."))
select(iris, Petal.Length, Petal.Width)
vars <- c("Petal.Length", "Petal.Width")
select(iris, one_of(vars))
df <- as.data.frame(matrix(runif(100), nrow = 10))
df <- tbl_df(df[c(3, 4, 7, 1, 9, 8, 5, 2, 6, 10)])
select(df, V4:V6)
select(df, num_range("V", 4:6))
# Drop variables
select(iris, -starts_with("Petal"))
select(iris, -ends_with("Width"))
select(iris, -contains("etal"))
select(iris, -matches(".t."))
select(iris, -Petal.Length, -Petal.Width)
# Rename variables:
# * select() keeps only the variables you specify
select(iris, petal_length = Petal.Length)
# Renaming multiple variables uses a prefix:
select(iris, petal = starts_with("Petal"))
# Reorder variables: keep the variable "Species" in the front
select(iris, Species, everything())
# * rename() keeps all variables
rename(iris, petal_length = Petal.Length)
# Programming with select ---------------------------------------------------
select_(iris, ~Petal.Length)
select_(iris, "Petal.Length")
select_(iris, lazyeval::interp(~matches(x), x = ".t."))
select_(iris, quote(-Petal.Length), quote(-Petal.Width))
select_(iris, .dots = list(quote(-Petal.Length), quote(-Petal.Width)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.