Description Usage Arguments Details Value Note Author(s)
Create a unique key ID variable
1 | key_creation(df, factor_vars = NULL)
|
df |
dataset to add a unique ID variable |
factor_vars |
factor variables reference |
This function allows you to add a unique key ID to the dataset based on the factor variables (or not)
"This function allows us to return original dataset with a new KEY variable based on:"
If factor_vars = NULL
bring a KEY variable as day_month_year_sequence from 1 to the length of the dataset
If factor_vars
is not NULL bring a KEY variable as day_month_year_concatenate the unique id for each level for each factor variable selected
The intention of this function is that in the future we use this new variable as an ID for merges.
If for some reason the key variable is not unique then the program re-ajust it, so filter those duplicated observations and concatenate them with the corresponding index number (from 1 to the length of the duplicated values).
If the dataset has a date variable then use this variable as reference but if not is going to create a new date variable reference
today()+(1:length(vector)) is: sequence of days from today to the day that represent the last element of the vector
today()+(1:length(vector))*days(-1) is: days(-1) invert the order, sequence this is from the day that represent the first element of the vector to yesterday "today()-1"
sort(today()+(1:length(df1$ID_REGION))*days(-1)) is: sorted day from the lowest to the gratest
Eduardo Trujillo
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.