View source: R/dataframe_tools.R
overwrite_df | R Documentation |
Uses regex to match and replace cell values. This function is meant for formatting
printed data; it's often useful to blank out NAs or other values to minimise visual
clutter when you are reading a table. For actual data-tidying applications, it's
safer to use dplyr::recode()
or dplyr::recode_factor()
.
overwrite_df(
df,
find = "^(NA||\\s+|0|-+|_+)$",
replace = "",
replace_na = TRUE
)
df |
(Dataframe) A dataframe. |
find |
(Character) A regex search pattern. |
replace |
(Character) The string used to overwrite the matching cells. |
replace_na |
(Logical) If |
By default, this function will replace cells consisting of NAs, spaces, empty strings, dashes, and underscores with an empty string.
A dataframe.
Desi Quintans (http://www.desiquintans.com)
test_df <-
data.frame(stringsAsFactors = FALSE,
name = c("insect1", "insect2", "insect3", "insect4", "insect5",
"insect6", "insect7", "insect8", "insect9", "insect10"),
family = c("Belidae", "Belidae", " ", "Coccinelidae", NA, "Coccinelidae",
"Braconidae", "_", "-", "Curculionidae"),
is_cool = c("TRUE", "TRUE", NA, "TRUE", "", "TRUE", "TRUE", "-", "_",
"TRUE")
)
test_df
overwrite_df(test_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.