Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional expression for if variable present in model

Tags:

r

What I want to do is to make a condition for if there is a certain variable in linear model

Example. If there is a B in a linear model

model <- lm(Y ~ A + B + C)

I want to do something. I have used the summary function before to refer to R-squared.

summary(model)$r.squared

Probably I am looking for something like this

if (B %in% summary(model)$xxx)

or

if (B %in% summary(model)[xxx])

But I can't find xxx. Please help =)

like image 938
Marcus R Avatar asked Jun 24 '26 19:06

Marcus R


1 Answers

Try this:

if ("B" %in% all.vars(formula(model))) ...
like image 94
G. Grothendieck Avatar answered Jun 27 '26 09:06

G. Grothendieck