![]() # `case_match()` is easier to use with numeric vectors, because you don't # need to turn the numeric values into names num_vec 1 20 3 40 NA case_match ( num_vec, 2 ~ 20, 4 ~ 40. default = NA) : #> `.default` must be a character vector, not `NA`. default = NA ) ) #> Error in recode(char_vec, a = "Apple", b = "Banana". try ( recode ( char_vec, a = "Apple", b = "Banana". default = NA ) #> "Apple" "Apple" "Apple" "Apple" NA NA "Banana" #> "Apple" "Banana" NA # Throws an error as `NA` is logical, not character. default = NA_character_ ) #> "Apple" "Apple" "Apple" "Apple" NA NA "Banana" #> "Apple" "Banana" NA case_match ( char_vec, "a" ~ "Apple", "b" ~ "Banana". default = char_vec ) #> "Apple" "Apple" "Apple" "Apple" "c" "c" "Banana" #> "Apple" "Banana" "c" # With `case_match()`, you don't need typed missings like `NA_character_` recode ( char_vec, a = "Apple", b = "Banana". ![]() Must be either length 1 or the same length asĬhar_vec "Apple" "Apple" "Apple" "Apple" "c" "c" "Banana" #> "Apple" "Banana" "c" case_match ( char_vec, "a" ~ "Apple", "b" ~ "Banana". ![]() default must be either length 1 or the same length as If not supplied and if the replacementsĪre not compatible, unmatched values are replaced with NA. If not supplied and if the replacements are ![]() If supplied, all values not otherwise matched willīe given this value. When named, the argument names should be the current values to be replaced, and theĪrgument values should be the new (replacement) values.Īll replacements must be the same type, and must have either x represents positions to look for in replacements. If not named, the replacement is done based on position i.e. x, these should be namedĪnd replacement is based only on their name.
0 Comments
Leave a Reply. |