| prep_data | R Documentation |
Standardize column names to "object_id", "account_id", "content_id", and "timestamp_share" and remove missing or duplicate shares.
prep_data(
x,
object_id = NULL,
account_id = NULL,
content_id = NULL,
timestamp_share = NULL,
drop_na = TRUE,
drop_duplicates = TRUE
)
x |
A data.table or an object that can be converted into a data.table. This is the dataset whose columns will be renamed. |
object_id |
The current name of the column that should be renamed to "object_id". If NULL, no renaming is performed on this column. |
account_id |
The current name of the column that should be renamed to "account_id". If NULL, no renaming is performed on this column. |
content_id |
The current name of the column that should be renamed to "content_id". If NULL, no renaming is performed on this column. |
timestamp_share |
The current name of the column that should be renamed to "timestamp_share". The data in this column should be either in UNIX format or in a "%Y-%m-%d %H:%M:%S" format. If conversion is unsuccessful, the function stops with an error. If NULL, no renaming or conversion is performed on this column. |
drop_na |
Remove rows missing a value in any available standardized column (default TRUE). Set to FALSE to retain them. |
drop_duplicates |
Remove duplicate shares after renaming and timestamp conversion (default TRUE). With all four standardized columns present, duplicates are determined by those columns; otherwise, exact duplicate rows are removed. Set to FALSE to retain duplicates. |
This function allows the user to specify the current names of columns in their data.table that they wish to rename to a standard format. The function checks for each parameter and renames the corresponding column in the data.table. If the parameter is NULL, no change is made to that column. The input is copied before renaming, so a supplied data.table is not changed by reference. By default, rows missing a value in any available standardized column are removed. When all four standardized columns are present, duplicates are identified by those four columns and the first row is kept. With a partial schema, only identical full rows are considered duplicates. Other columns are retained and their missing values do not cause rows to be removed. For the 'timestamp_share' column, the function expects the format to be either UNIX format (integer representing seconds since the Unix epoch) or "%Y-%m-%d %H:%M:%S". If the 'timestamp_share' is in a different format, the function attempts to convert it to UNIX format using base R functions.
A data.table with standardized columns and, by default, missing and duplicate shares removed. The input object is not modified.
dt <- data.table::data.table(original_object_id = c(1, 1, NA),
original_account_id = c("a", "a", "b"))
prep_data(dt, object_id = "original_object_id", account_id = "original_account_id")
prep_data(dt, object_id = "original_object_id", account_id = "original_account_id",
drop_na = FALSE, drop_duplicates = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.