r - How to use dplyr to make several simple regressions using always the same independent variable but changing the dependent one? -


i hope not simplest question. need make simple regression (yes, simple one: y = + bx + epsilon). data frame such each column has 1 variable (and each column has 20 rows (observations)). problem first 10 columns y1 y10 , last 1 independent variable.

so, have run 10 regressions, changing yi (i = 1,...10). example:

y1 = + bx + epsilon y2 = + bx + epsilon ... y10 = + bx + epsilon

(yi , x vectors (20 x 1), it's exercise)

i can 1 one, thinking them in 1 command. not veteran in programming , thinking if dplyr me this.

i looking suggestions.

thank you.

you can try

lapply(d1[paste0('y',1:10)], function(y) lm(y~d1[,'x'])) 

where d1 dataset


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -