Description Usage Arguments Value Examples
View source: R/column_based_recode.R
Recode NA as based on Other Columns
1 2 3 4 5 6 7 8 9 10 |
df |
A data.frame object for which recoding is to be done. |
criterion |
Currently supports one of all_na or any_na to index rows that are either all NA or contain any NA. |
values_from |
Character. Name of column to get the original values from |
values_to |
Character New column name for the newly recoded values. Defaults to the same name if none is supplied. |
value |
The value to convert to 'NA'. We can for instance change "n/a" to 'NA' or any other value. |
pattern_type |
One of contains', 'starts_with' or 'ends_with'. |
pattern |
A character pattern to match |
case_sensitive |
Defaults to FALSE. Patterns are case insensitive if TRUE |
A 'data.frame' object with target 'NA' values replaced.
1 2 3 4 5 | df <- structure(list(id = 40:43, v1 = c(NA, 1L, 1L, 1L), v2 = c(NA, 1L, 1L, 1L),
v3 = c(NA, 2L, NA, 1L),
test = c(1L, 2L, 1L, 3L)), class = "data.frame", row.names = c(NA, -4L))
# recode test as 0 if all NA, return test otherwise
column_based_recode(df,values_from = "test", pattern_type = "starts_with", pattern="v")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.