Hi!

I am new to R programming and I am stuck for some time on a certain problem.

I have a dataframe where I have 7 columns. The first column are bins. I define columns 2-4 as one subset (one sample) and columns 5-7 as another sample. I want to perform statistical tests on these samples fpr each bin (so for each row). Here is a photo for better understanding:

So e.g. I want to perform a test: I take data of row 1 (9,75) and compare the col 2-4 with col 5-7 and see if there is for example a difference in variance. I want to perform this test in each row, always comparing the same set of cols with each other.

I did this with the t-test and it worked. But for the Bartlett test I stumble upon some difficulties due to the syntax. So I tried this but I get an error that all observations are in the same group:

Note: I save the p-value of the b.test in a new column.

# perform Bartlett test

M1M2_Data_log10$P_Value_Bartlett <- NA

for (i in 1:nrow(M1M2_Data_log10)){

M1M2_Data_log10$P_Value_Bartlett[i] <- bartlett.test(unlist(M1M2_Data_log10[i, 2:7]),rep(LETTERS[1:2], each=3))$p.value

} # transforms row i into a vector, rep defines 2 groups, then bartlett test has a numeric vector and grouping variable to run the test