The folrows() function extracts a specified number of consecutive rows,
including the starting row, from a dataframe.
Rows are selected consecutively from randomly chosen starting positions.
The function ensures that the selected rows fall within the valid row range of the dataframe.
Arguments
- .data
The dataframe from which rows are to be extracted.
- n
The number of consecutive rows to be extracted, including the starting row. Default is 5.
- nb_sample
The number of random starting positions to be sampled. Default is 1.
Value
A dataframe containing the consecutive rows extracted from the randomly chosen starting positions.
Examples
# Extract 3 consecutive rows starting from a random position in the dataset
folrows(esmdata_sim, n = 3)
#> dyad role obsno id age cond_dyad scheduled sent
#> 3618 26 2 48 52 25 condB 2018-10-17 10:00:03 2018-10-17 10:00:07
#> 3619 26 2 49 52 25 condB 2018-10-17 11:00:05 2018-10-17 11:00:15
#> 3620 26 2 50 52 25 condB 2018-10-17 12:00:15 2018-10-17 12:00:34
#> start end contact PA1 PA2 PA3 NA1 NA2 NA3
#> 3618 2018-10-17 10:00:27 2018-10-17 10:02:57 0 1 6 34 26 1 35
#> 3619 2018-10-17 11:00:24 2018-10-17 11:02:00 0 1 1 33 27 2 23
#> 3620 2018-10-17 12:00:53 2018-10-17 12:02:50 0 1 1 29 42 13 21
#> location
#> 3618 B
#> 3619 E
#> 3620 D
# Extract 4 consecutive rows starting from 2 random positions in a custom dataframe
folrows(esmdata_sim, n = 4, nb_sample = 2)
#> dyad role obsno id age cond_dyad scheduled sent
#> 3605 26 2 35 52 25 condB 2018-10-14 11:59:57 2018-10-14 12:00:07
#> 3606 26 2 36 52 25 condB 2018-10-15 08:00:07 2018-10-15 08:00:40
#> 3607 26 2 37 52 25 condB 2018-10-15 09:00:02 2018-10-15 09:00:06
#> 3608 26 2 38 52 25 condB 2018-10-15 10:00:00 2018-10-15 10:00:12
#> 23 1 1 23 1 40 condB 2018-10-21 10:00:07 2018-10-21 10:00:10
#> 24 1 1 24 1 40 condB 2018-10-21 11:00:13 2018-10-21 11:00:15
#> 25 1 1 25 1 40 condB 2018-10-21 12:00:09 2018-10-21 12:00:20
#> 26 1 1 26 1 40 condB 2018-10-22 08:00:20 2018-10-22 08:00:25
#> start end contact PA1 PA2 PA3 NA1 NA2 NA3
#> 3605 2018-10-14 12:00:28 2018-10-14 12:02:57 0 1 1 16 49 6 22
#> 3606 2018-10-15 08:01:00 2018-10-15 08:02:23 0 1 1 22 35 12 27
#> 3607 2018-10-15 09:00:20 2018-10-15 09:02:21 0 1 1 16 42 9 35
#> 3608 2018-10-15 10:00:29 2018-10-15 10:01:56 0 1 1 22 30 1 28
#> 23 2018-10-21 10:00:20 2018-10-21 10:01:46 0 23 14 17 1 2 79
#> 24 2018-10-21 11:00:18 2018-10-21 11:01:45 0 25 27 29 1 10 72
#> 25 2018-10-21 12:00:43 2018-10-21 12:01:05 0 23 22 45 1 15 73
#> 26 2018-10-22 08:00:31 2018-10-22 08:02:14 0 21 8 38 1 1 70
#> location
#> 3605 B
#> 3606 B
#> 3607 D
#> 3608 C
#> 23 E
#> 24 A
#> 25 D
#> 26 B
