emilioxavier / theHUB

https://theHopefulBox.com/
Other
2 stars 0 forks source link

modify `convert.fromto()` to commodate `NA`s and exisiting `to` values #37

Closed emilioxavier closed 6 months ago

emilioxavier commented 6 months ago

Hi Please update the convert.fromto() function to retain NAs and existing to values or values not matching the from column of the fromto.tb. For example:

examples

states.tb <- tibble(name=c("maine", "michigan", "ohio"), abbrev=c("ME", "MI", "OH"))
address.state <- c(NA, "michigan", NA, "ohio", "PA", "ME", "maine", "WA", "pennslyvania")

YesNo.tb <- tibble(long=c("Yes", "No"), short=c("Y", "N"))
set.seed(13)
YN.values.1 <- sample(x=c("Yes", "No"), size=10, replace=TRUE)
YN.values.2 <- c(YN.values.1, "Y", "N", "M")

address.state

theHUB::convert.fromto(responses=address.state, fromto.tb=states.tb, from="name", to="abbrev")
# [1] NA   "MI" NA   "OH" NA   NA   "ME" NA   NA 

YN.values

theHUB::convert.fromto(responses=YN.values.1, fromto.tb=YesNo.tb, from="long", to="short")
# [1] "N" "Y" "N" "Y" "N" "Y" "N" "N" "N" "N"

theHUB::convert.fromto(responses=YN.values.2, fromto.tb=YesNo.tb, from="long", to="short")
# [1] "N" "Y" "N" "Y" "N" "Y" "N" "N" "N" "N" NA  NA  NA 

Thank you!