In my data frame i have many columns which is dependent on first column. for example in question one i have to ask if a person have mobile the answer should be yes or no and in another question we are asking which model if they answer yes to first question.
so i want to create a new data frame which text for if a person answered first question in Yes or any then there should be text in second question which is dependent on first question. for example i have shown in picture
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
}