I have two data frames:
x = data.frame(Var1= c("A", "B", "C", "D","E"),Var2=c("F","G","H","I","J"),
Value= c(11, 12, 13, 14,18))
y = data.frame(A= c(11, 12, 13, 14,18), B= c(15, 16, 17, 14,18),C= c(17, 22, 23, 24,18), D= c(11, 12, 13, 34,18),E= c(11, 5, 13, 55,18), F= c(8, 12, 13, 14,18),G= c(7, 5, 13, 14,18),
H= c(8, 12, 13, 14,18), I= c(9, 5, 13, 14,18), J= c(11, 12, 13, 14,18))
Var3 <- rep("time", each=length(x$Var1))
x=cbind(x,Var3)
time=seq(1:length(y[,1]))
y=cbind(y,time)
> x
Var1 Var2 Value Var3
1 A F 11 time
2 B G 12 time
3 C H 13 time
4 D I 14 time
5 E J 18 time
> y
A B C D E F G H I J time
1 11 15 17 11 11 8 7 8 9 11 1
2 12 16 22 12 5 12 5 12 5 12 2
3 13 17 23 13 13 13 13 13 13 13 3
4 14 14 24 34 55 14 14 14 14 14 4
5 18 18 18 18 18 18 18 18 18 18 5
Looking at x
DF, I have variable A
and F
as the first row. I want to select these two variables in y
DF and implement a simple regression: lm(A ~ F, data = y)
, and save the result in the first position of a list. I will do the same with the second row of x
DF implementing a regression lm(B ~ G, data = y)
.
How could I match variables names in x
to data in y
for a regression?
Revised question: how about a more complicated regression Var1 ~ Var2 + Var3
?