I have a main dataframe.I need to mutate and create new variables based on various conditions.New variable name and conditions are dynamic. I managed to get the conditions as a column in another dataframe.The problem i need to solve is to evaluate the statements in main dataframe.
eg
x <- runif(10)
#convert to DF
DF <- as.data.frame(x)
DF[1:15] <- sapply(1:15, "+", rnorm(5,60,15))
names(DF) <- paste0("col", 1:15)
-- DF is main dataframe
indx1<-c(1:4)
condition<-c('mutate(AA1=ifelse(col1<.5&col6>.1,1,0))','mutate(CA1=ifelse(col11<.7 & col5>.2,1,0))',
'mutate(AB1=ifelse(col12<.1 & col8>.2,1,0))','mutate(C1=ifelse(col3<.56 & col7>.2,1,0))')
cond_df=data.frame(indx1,condition)
-- cond_df is the condition DF
indx1 condition
1 1 mutate(AA1=ifelse(col1<.5&col6>.1,1,0))
2 2 mutate(CA1=ifelse(col11<.7 & col5>.2,1,0))
3 3 mutate(AB1=ifelse(col12<.1 & col8>.2,1,0))
4 4 mutate(C1=ifelse(col3<.56 & col7>.2,1,0))
i need to execute each of the condition in main dataframe so that new variables AA1,CA1 -- will be created. Any assistance would be really helpful.