Dataframes containing the same variable names
If you have several different dataframes containing the same variable names (say x and y) then the simplest way to ensure that the correct variables are used in the modelling is to name the dataframe in the function call:
model<-lm(y ~ x,data=correct.frame)
The alternative is much more cumbersome to type:
model<-lm(correct.frame$y ~ correct.frame$x)
Get The R Book now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.