Home > database >  Iterative tests on multiple rows from 2 columns in rstudio
Iterative tests on multiple rows from 2 columns in rstudio

Time:10-30

I have a dataset of 2 columns and 100 rows. I want to apply t-tests on every 10 rows of the 2colums, for example: test 1 for values[1:10] of columns A and B, test 2 for values [2:11] of columns A and B, test 3 for values[3:12] of columns A and B, etc, until test 91 for values [91: 100] of columns A and B. Now my way is like this for every test:

    RC.1 <- RC9[1:10]
    RM.1 <- RM9[1:10]
    easting.1 <- strip9$xcoord[1:10]
    northing.1 <- strip9$ycoord[1:10]
    coord1 <- data.frame(easting.1, northing.1)
    modified.p1 <- modified.ttest(RC.1, RM.1, coord1)

Anyone knowns an efficient way to do it, instead of typing 91 tests manually?

Thanks.

CodePudding user response:

You may try this approach with a for loop -

n <- 10
k <- NROW(strip9) - n   1
result <- vector('list', k)

for(i in 1:k) {
  index <- i:(i n-1)
  RC.1 <- RC9[index]
  RM.1 <- RM9[index]
  easting.1 <- strip9$xcoord[index]
  northing.1 <- strip9$ycoord[index]
  coord1 <- data.frame(easting.1, northing.1)
  result[[i]] <- modified.ttest(RC.1, RM.1, coord1)
}

result
  • Related