-5

I am trying to use the coef function in r, and I need to know how to use this function to extract columns from a dataset. I tried coef(rain$spring, rain$autumn) but it returned a message saying I could not use $. The dataset is rain, the variables are spring and autumn. There is another dataset spring so I cannot simply attach the two variables.

Thanks!

cmaher
  • 5,100
  • 1
  • 22
  • 34
AIN
  • 1
  • 2
  • 2
    Please provide a reproducible example. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example . Also this question is not related to rstudio. – JRR Apr 10 '18 at 20:39

1 Answers1

2

Please read the help page before you post a question. ?coef says that:

coef is a generic function which extracts model coefficients from objects returned by modeling functions

Therefore, you need to run a linear model using lm() on your data-set, then extract the coefficients from the model:

coef(lm(...))
divibisan
  • 11,659
  • 11
  • 40
  • 58