Hi,

I need help to extract similar data from various excel sheets into R through a loop for a regression analysis of grade 8, 9 and 10 students' height against their mothers' and fathers' height .

The excel file name is "height.xlsx". The three sheet names are "Grade 8", "Grade 9" and "Grade 10". The column names are "Student_Height" for dependent variable data, and "Mother_Height" and "Father_Height" for independent data.

I am running the following code:

A = getSheetNames("height.xlsx")

for (i in c(1:3))

{

my_sheet = read_excel("height.xlsx", sheet = A[i])

X = data.frame(Mother_Height,Father_Height)

Y = Student_Height

reg_fit = ln(Y ~ X)

}

Now the problem is that while running through the loop, X and Y are stuck with the first sheet and are not going to the second and third sheets.

Can someone please help me fix this. Thanks