year_cols | R Documentation |
It is sometimes helpful to know which columns are years.
This function returns a set of indices
(or, optionally, the names) of columns in .df
that represent years.
year_cols(
.df,
year_pattern = "^-?\\d+$",
year = IEATools::iea_cols$year,
return_names = FALSE
)
.df |
A data frame with years spread to the right in columns. |
year_pattern |
A regex pattern that identifies years. Default is " |
year |
See |
return_names |
A boolean which tells whether names are returned instead of column indices.
Default is |
The default year_pattern
is "^-?\\d+$
", which matches columns whose names
have zero or one negative signs followed by any number of digits.
If .df
is tidy, it may have a "Year" column which is included in the return value.
To disable this behavior, set year = NULL
.
a vector of column indices (when return_names = FALSE
, the default) or
a vector of column names (when return_names = TRUE
)
for those columns that represent years.
DF <- data.frame(a = c(1, 2), `1967` = c(3, 4), `-42` = c(5, 6), check.names = FALSE)
DF %>% year_cols()
DF %>% year_cols(return_names = TRUE)
DF2 <- data.frame(data.frame(a = c(1, 2), Year = c(1967, 2020)))
DF2 %>% year_cols(return_names = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.