Hello everyone!
I am currently working with the built-in data set "iris". I have calculated separate regressions for the three types of plant species like this and it worked:
reg1= with(iris[iris$Species=="setosa",], lm(Sepal.Width~Sepal.Length))
reg2= with(iris[iris$Species=="versicolor",], lm(Sepal.Width~Sepal.Length))
reg3= with(iris[iris$Species=="virginica",], lm(Sepal.Width~Sepal.Length))
Now, I am wondering if it is also possible to calculate three sub-regressions using the by-function in R.
I have tried it like this but I only receive error messages:
b<- by(iris, iris$Species, function(x){
regby<- lm(Sepal.Width~Sepal.Length)}
Does anyone have any tips for me.
Thank you. Your answers are very much appreciated.