0

First I would like to apologise in advance. I am new to programming so my questions might be obvious and/or naive.

I am running a two sided Kolmogorov–Smirnov test on 26 columns of data using the code below:

#a bit of the data
library("dgof")

df1 <- data.frame(a = c(0,0.324675325,0.324675325,2.272727273,1.298701299,2.922077922,2.922077922,4.545454545,4.545454545,3.896103896,5.194805195),
                   b = c(0.110619469,0.110619469,0,0.221238938,0.884955752,2.654867257,3.761061947,5.752212389,5.19),
                   cc = c(0.110619469,0.110619469,0,0.221238938,0.884955752,2.654867257,3.761061947,5.752212389,5.19),
                   d = c(0,0,0,0,1.550387597,1.162790698,5.426356589,5.03875969,2.325581395,2.325581395,3.488372093,5.813953488,3.100775194,5.426356589,6.589147287,5.426356589,3.875968992,5.426356589))

df2 <- data.frame(a = c(0,0.324675325,0.324675325,2.272727273,1.298701299,2.922077922,2.922077922,4.545454545,4.545454545,3.896103896,5.194805195),
                   b = c(0.110619469,0.110619469,0,0.221238938,0.884955752,2.654867257,3.761061947,5.752212389,5.19),
                   cc = c(0.110619469,0.110619469,0,0.221238938,0.884955752,2.654867257,3.761061947,5.752212389,5.19),
                   d = c(0,0,0,0,1.550387597,1.162790698,5.426356589,5.03875969,2.325581395,2.325581395,3.488372093,5.813953488,3.100775194,5.426356589,6.589147287,5.426356589,3.875968992,5.426356589))

for(i in 1:(ncol(df1)-2)){
        for(j in (i+1):(ncol(df2)-1)){
                print(paste0("Trial.", i, " - Trial.", j))
                ks_result <- ks.test(df1[, i],
                                     df2[, j],
                                     alternative="two.sided")
                print(ks_result)
        }
}  

(df1 and df2 contain the exact same data - this is the only way I could find of getting the ks.test to compare all data)

I would like to put all of the results into a data.frame but I have no idea where to even start with this.

I really appreciate any help you can give in putting the results into a table (preferably by keeping as much of the code I have.

Thanks

  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 11 '22 at 16:43
  • See also: https://stackoverflow.com/questions/17158395/storing-output-from-nested-for-loops-in-r or https://stackoverflow.com/questions/22845846/using-a-list-to-store-results-of-a-double-loop-for-loop-in-r or https://stackoverflow.com/questions/62182167/save-results-in-nested-loop-using-a-function on saving results from nested loops – MrFlick Jul 11 '22 at 16:45
  • I have edited the question to help with reproduciblity – Tom Lawrence Jul 11 '22 at 16:55
  • @TomLawrence the data you include contain uneven number of elements for the columns (i.e. cannot be reproduce as a data.frame). Please verify. – Adam Quek Jul 11 '22 at 22:57

0 Answers0