Dear R forum I have a dataframe (of prices) as given below -
dat = data.frame(company = rep(c("A", "B", "C", "D", "index"), each = 5), prices = c(runif(5, 10, 12), runif(5, 108, 112), runif(5, 500, 510), runif(5, 40, 50), runif(5, 1000, 1020))) company prices 1 A 10.61727 2 A 10.51892 3 A 11.80495 4 A 11.15243 5 A 10.77543 6 B 111.23817 7 B 109.19825 8 B 108.80053 9 B 110.79876 10 B 108.84385 11 C 504.71801 12 C 504.11778 13 C 502.89416 14 C 500.65996 15 C 502.26748 16 D 42.35901 17 D 43.71947 18 D 46.46092 19 D 43.62220 20 D 48.47480 21 index 1017.24476 22 index 1002.88139 23 index 1005.16148 24 index 1014.54480 25 index 1014.12103 I need to find the beta of A, B, C and D w.r.t index. Beta between two variables X and Y (where Y is dependent) is given by, beta = coef(lm(Y ~ X))[2] Any guidance is appreciated. With regards Katherine [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.