knitr::opts_chunk$set(echo = TRUE) library(epiuf)
The aim of this function is to take a variable and set specified values to NA. Uses gsub to acheive this. Values to search can be specified in list, or in string format. Usual nomenclature applies to specify beginning, end, ect. A default list is available that is used if no values are specified or that can be join to the specified value list.
# create example dataset for testing df <- data.frame(CharacterVar = c("unknown", "do not know", "other", "dnk", "na", "nd", "nsp", "ne zna", "testdnk", "dnktest", "test", "not test", "3", "4"), NumberVar = c(1, 2, 3, 4, 1, 2, 3, 4,1, 2, 3, 4, 1, 2) )
df$test <- applyNA(df, CharacterVar) # only default list # Should make 7 conversions df$test <- applyNA(df, CharacterVar, "^test$") # only specified # Should make 1 conversions df$test <- applyNA(df, CharacterVar, "^test$", join=TRUE) # both default and specified # Should make 8 conversions df$test <- applyNA(df, CharacterVar, "test", join=TRUE) # both default and specified # Should make 8 conversions df$test <- applyNA(df, CharacterVar, c("^test$","^other*")) # list of search values # Should make 2 conversions df$test <- applyNA(df, CharacterVar, "test,other") # list of search values # Should make 2 conversions df$test <- applyNA(df, CharacterVar, "3") # list of search values # Should make 1 conversions df$test <- applyNA(df, CharacterVar, "3,4") # list of search values # Should make 2 conversions df$test <- applyNA(df, CharacterVar, c(3,4)) # list of search values # Should make 2 conversions df$test <- applyNA(df, NumberVar, 3) # number value # Should make 3 conversions df$test <- applyNA(df, NumberVar, c(3,1)) # list of numbers # Should make 7 convers df$test <- applyNA(df, NumberVar, "3,1") # list of numbers # Should make 7 convers
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.