I guess this question has been asked somewhere. Although I cannot find one. Please help me out. I need to output a list but only show maybe the first element of the list while the other elements are invisible. Though one is able to access them.
Allow me to give an example.
s=lm(iris)
s
Call:
lm(formula = iris)
Coefficients:
(Intercept) Sepal.Width Petal.Length Petal.Width
2.1713 0.4959 0.8292 -0.3152
Speciesversicolor Speciesvirginica
-0.7236 -1.0235
length(s)
[1] 13
Here We see that when using lm
function, the output is a list of length 13. We can access all the elements we want from s
by simply using the dollar sign. But at the same time we only see call and the coefficients, we do not see all the other elements like the residuals, fitted values etc. How can I implement this on my function?
For the example above, The object returned is of class lm. I would like to write a function not necessarily outputting an lm object.
Thank you