yesNoBool {quickcode} | R Documentation |
Convert Yes/No to Binary or Logical
Description
Seamlessly convert a yes or no to either a binary or logical output
Usage
yesNoBool(
table,
fldname,
out = c("change", "append", "vector"),
type = c("bin", "log")
)
Arguments
table |
data frame |
fldname |
field name in the data frame |
out |
output form, choices - change, append, vector |
type |
output type, choices - bin, log |
Details
type - "bin" for binary, and "log" for logical
Value
converted Yes/No entries into 1/0 or TRUE/FALSE
Examples
# Declare data for example
usedata <- data.frame(ID = 1:32)
usedata #view the dataset
usedata$yess = rep(c("yes","n","no","YES","No","NO","yES","Y"),4) #create a new column
usedata #view the modified dataset
# Set all yess field as standardize boolean
# Task: convert the "yess" column content to 1/0 or TRUE/FALSE
# Notice that you have add the column name with or without quotes
yesNoBool(usedata,yess, type="bin") #set all as binary 1/0
yesNoBool(usedata,"yess", type="log") #set all as logical TRUE/FALSE
# Task: By default, the 'out' argument is set to "change"
# means that the original data field will be
# replaced with the results as above
# In this example, set the out variable to
# append data frame with a new column name containing the result
yesNoBool(usedata,yess,"append")
#or yesNoBool(usedata,"yess","append")
# In this example, return as vector
yesNoBool(usedata,yess,"vector")
#or yesNoBool(usedata,"yess","vector")
# Task: Return result as logical
yesNoBool(usedata,"yess",type = "log")
[Package quickcode version 0.9.1 Index]