find_starts | R Documentation |
Finds values or indices of values that are not the same as the previous value.
E.g. to use with the "l_starts"
method.
Wraps differs_from_previous()
.
find_starts(
data,
col = NULL,
return_index = FALSE,
handle_na = "ignore",
factor_conversion_warning = TRUE
)
data |
N.B. If checking a N.B. If |
col |
Name of column to find starts in. Used when |
return_index |
Whether to return indices of starts. (Logical) |
handle_na |
How to handle "ignore"Removes the "as_element"Treats all Numeric scalarA numeric value to replace |
factor_conversion_warning |
Throw warning when
converting |
vector
with either the start values or the indices of the start values.
N.B. If `data`
is a grouped data.frame
,
the output is a list
of vector
s.
The names are based on the group indices
(see dplyr::group_indices()
).
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other l_starts tools:
differs_from_previous()
,
find_missing_starts()
,
group_factor()
,
group()
# Attach packages
library(groupdata2)
# Create a data frame
df <- data.frame(
"a" = c("a", "a", "b", "b", "c", "c"),
stringsAsFactors = FALSE
)
# Get start values for new groups in column 'a'
find_starts(df, col = "a")
# Get indices of start values for new groups
# in column 'a'
find_starts(df,
col = "a",
return_index = TRUE
)
## Use found starts with l_starts method
# Notice: This is equivalent to n = 'auto'
# with l_starts method
# Get start values for new groups in column 'a'
starts <- find_starts(df, col = "a")
# Use starts in group() with 'l_starts' method
group(df,
n = starts, method = "l_starts",
starts_col = "a"
)
# Similar but with indices instead of values
# Get indices of start values for new groups
# in column 'a'
starts_ind <- find_starts(df,
col = "a",
return_index = TRUE
)
# Use starts in group() with 'l_starts' method
group(df,
n = starts_ind, method = "l_starts",
starts_col = "index"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.