I want a function which can validate text in two column like and on the basis of two column it can create a new data frame with columns.
Criteria: for example in below sample data frame i am asking two question if first question answer is Yes then i need to validate there should be response in second column also for response Yes in first column.
Then i need to create a new data frame which confirms the above criteria follows. function is required so that i can apply that to many questions.
going forward i will create a summary tables with all the new columns.
df <- data.frame("have mobile" = c("Yes", "No", "No", "No", "No", "Yes", "No", "Yes", "Yes", "No", "No", "No", "Yes"),
"Which model" = c("c1", NA, NA, NA, NA, "c2", NA, "c2", "c3", NA, NA, NA, "c3"))
func1 <- function(df,col_1,col_var_1,col2,col_var2){
df[new_col1] <- ifelse(df[col_1]==col_var_1,df[col2]==is.na(df[col2]),"should be ok","")
df
}
