New dataframe from every nth row of old dataframe subsets

I'm trying to create a new dataframe by selecting every 7th row from my old dataframe. Specifically, I want every 7th row from the subsets "Primer", "E" and "R2"

The current (old) dataframe looks like this:

print(total)
  Conc Primer   Ct1   Ct2   mean     slope          E        R2
1  1.00000    TBP 26.58 26.04 26.310 -1.588132  3.2625604 0.5994649
2  0.20000    TBP 28.46 28.32 28.390 -1.588132  3.2625604 0.5994649
3  0.04000    TBP 31.49 31.14 31.315 -1.588132  3.2625604 0.5994649
4  0.00800    TBP 33.90 32.18 33.040 -1.588132  3.2625604 0.5994649
5  0.00160    TBP 34.81 38.72 36.765 -1.588132  3.2625604 0.5994649
6  0.00032    TBP    NA    NA    NaN -1.588132  3.2625604 0.5994649
7  1.00000 EBF1_A 28.11 27.23 27.670 -0.791270 17.3565499 0.7927938
8  0.20000 EBF1_A 29.25 29.25 29.250 -0.791270 17.3565499 0.7927938
9  0.04000 EBF1_A 32.04 30.90 31.470 -0.791270 17.3565499 0.7927938
10 0.00800 EBF1_A 31.96 32.49 32.225 -0.791270 17.3565499 0.7927938
11 0.00160 EBF1_A 32.42 32.68 32.550 -0.791270 17.3565499 0.7927938
12 0.00032 EBF1_A    NA    NA    NaN -0.791270 17.3565499 0.7927938
13 1.00000 EBF1_B 27.80 27.72 27.760 -1.097899  7.1438682 0.7634541
14 0.20000 EBF1_B 29.17 29.45 29.310 -1.097899  7.1438682 0.7634541
15 0.04000 EBF1_B 31.89 32.07 31.980 -1.097899  7.1438682 0.7634541
16 0.00800 EBF1_B 32.76 32.76 32.760 -1.097899  7.1438682 0.7634541
17 0.00160 EBF1_B    NA    NA    NaN -1.097899  7.1438682 0.7634541
18 0.00032 EBF1_B    NA    NA    NaN -1.097899  7.1438682 0.7634541
19 1.00000 EBF2_A 29.28 29.50 29.390 -6.145888  0.4544889 0.6973744
20 0.20000 EBF2_A 31.69 30.70 31.195 -6.145888  0.4544889 0.6973744
21 0.04000 EBF2_A 34.00 34.75 34.375 -6.145888  0.4544889 0.6973744
22 0.00800 EBF2_A 35.24 35.20 35.220 -6.145888  0.4544889 0.6973744
23 0.00160 EBF2_A 36.04 38.33 37.185 -6.145888  0.4544889 0.6973744
24 0.00032 EBF2_A    NA    NA    NaN -6.145888  0.4544889 0.6973744

I thought to begin with learning how to extract every 7th element from the dataframe subset, before entertaining the idea of turning it into a dataframe. My idea was to use total[seq(1, nrow(total$Primer), 7), ] to print the 7th element of this dataframe subset, but it just returns Error in seq.default(1, nrow(total$Primer), 7) : 'to' must be of length 1

Any suggestions?



Read more here: https://stackoverflow.com/questions/67386713/new-dataframe-from-every-nth-row-of-old-dataframe-subsets

Content Attribution

This content was originally published by ShadH at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: