r - How to test if a formula is one-sided? -
i need test if formula one-sided (e.g. ~ a
rather a~b
).
right i'm doing this:
test <- list( ~ + b, ~ b + c, b + c ~ ) isonesided <- function(form) length(form)==2 && sum(grepl("~",form))==1 > sapply(test,isonesided) [1] true false false
is there better way? i'm worried there types of formulae don't know elude test.
i use terms
function , extract response attribute:
test <- list( ~ + b, ~ b + c, b + c ~ ) sapply( test , function(x) attr( terms(x) , "response" ) == 0 ) # [1] true false false
edit
as @arun points out terms
can't expand formula object special .
in without knowing data.frame
special refers to. workaround include dummy data.frame
in terms
function call:
## if want expand '.' in b + c ~ . test <- list( ~ + b, ~ b + c, b + c ~ , b + c ~ . , . ~ b + c ) sapply( test , function(x) attr( terms(x , data = data.frame(runif(1))) , "response" ) == 0 ) # [1] true false false false false
Comments
Post a Comment