Created
September 7, 2010 22:19
-
-
Save bullfight/569253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extract.formula<-function(formu){ | |
if (!is(formu,"formula")) | |
stop("X should be a valid formula of form \n y ~ x1 + x2 | conditional") | |
resp <- formu[[2]] | |
if( length(formu[[3]]) < 2 ){ formu <- formu }else{ formu <- formu[[3]] } | |
flattener <- function(f) {if (length(f)<3) return(f); | |
c(Recall(f[[2]]),Recall(f[[3]]))} | |
if (formu[[1]] == '|'){ | |
condi <- formu[[3]] | |
vars <- flattener(formu[[2]]) | |
}else if(formu[[1]] == '+' & length(formu) < 4){ | |
condi <- NA | |
vars <- c(formu[[2]], formu[[3]]) | |
}else if(length(formu[[3]]) < 2){ | |
condi <- NA | |
vars <- formu[[3]] | |
} | |
list(resp=resp,condi=condi,vars=vars) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment