Description Usage Arguments Value Examples
fill_na
fills in any NA
rows in a data.frame
column with the corresponding values from another column in
the same data.frame. It will coerce the column with NA
into the
same type as the column used to fill.
This function does not work well with factors.
1 |
df |
data.frame |
na_col |
column in |
fill_col |
column in |
Returns a data.frame
with NA
in a specific
column filled with values from another column.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # make data.frame with NA
my_data <- data.frame(name1 = c("Bob", "Jane", "Henry", "Sue"),
name2 = c("Mary", NA, "Tim", NA),
stringsAsFactors = FALSE)
# fill NA in names2
result <- fill_na(df = my_data, na_col = "name2", fill_col = "name1")
# make a another data.frame with NA
my_data <- data.frame(num1 = c(1, 2, 3),
num2 = c(3, 3, NA))
# fill NA in num2
result <- fill_na(df = my_data, na_col = "num2", fill_col = "num1")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.