Create dataframe with different length coloumns – General

I have csv files named 5-1-1_RRIntervals, 5-1-2_RRIntervals, 5-1-3_RRIntervals, … 15-15-4_RRIntervals, 15-15-5_RRIntervals.
They look like this:

timestamp, rr, since_start

1680519258168,725,372433
1680519258175,662,373095
1680519259158,681,373776
1680519261138,698,374474
1680519261145,678,375152
1680519261154,651,375803
1680519262127,666,376469
1680519263078,699,377168
1680519263084,746,377914
1680519264108,714,378628
…
I have the following code:

big_table <- data.frame()

firsts <- c(“5”)
for (first in firsts) {
for (third in 1:5) {
SI_combined <- c()
for (second in 1:15) {
file_name <- paste(first, second, third, sep = ‘-‘)

  if (file.exists(paste(file_name, "RRIntervals.csv", sep = '_'))) {
    data <- read.csv(paste(file_name, "RRIntervals.csv", sep = '_'))
    middle_col <- adattar[2]
    rr_intervals_raw <- adatok[-1,]
    rr_intervals <- round(rr_intervals_elso, digits = -1)
    
    mxdmn <- 0
    mo <- 0
    
    bins <- seq(0, 1500, by = 50)
    SI_values <- c()
    summation <- c()
    
    for (i in 1:length(rr_intervals)) {
      summation <- c(summation, rr_intervals[i])
      
      if (sum(summation) >= 30000) {
        mxdmn <- max(summation) - min(summation)
        mo <- Mode(summation)
        
        data_binned <- cut(summation, breaks = bins, right = TRUE, include.lowest = TRUE)
        bin_counts <- table(data_binned)
        
        x_bin <- cut(mo, breaks = bins, right = TRUE, include.lowest = TRUE)
        helyes_bin <- bin_counts[x_bin]
        összes_száma <- length(osszeg)
        Amo <- (helyes_bin / összes_száma) * 100
        SI <- Amo * 1000000 / (2 * mo * mxdmn)
        
        SI_values <- c(SI_values, SI)
      
        
        summation <- c()
      }
    }
    SI_combined <- c(SI_combined, SI_values)
  }
}

}
}

I want to add the five SI_combined to the big_table dataframe as coloumns, but they have different length. The rest should be filled with NA, but I could not manage it.
And I want to name the coloumns according to the “third” value (in the second for loop).

Thanks for the help.

Read more here: Source link