Description Usage Arguments Examples
pad_gaps
removes pupil size measurements that border gaps in the data.
1 2 3 4 5 6 7 8 |
pupil |
A numeric vector of pupil size measurements. |
time |
A vector containing the timestamps associated with the pupil size measurements. |
gap_minimum |
A numeric value describing the minimum gap duration. |
padding |
A numeric value describing by how much gaps should be padded. |
padding_before |
A numeric value describing by how much gaps should be padded before a gap. |
padding_after |
A numeric value describing by how much gaps should be padded after a gap. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # Load the "dplyr", "tidyr", and "ggplot2" packages:
library(dplyr)
library(tidyr)
library(ggplot2)
# Example 1: Artificial data
# Create some artificial data:
data <- tibble(
time = 1:8,
pupil_left = c(3.11, 3.13, 3.16, NA, NA, NA, 3.16, 3.12),
pupil_right = c(2.92, 2.95, 2.98, NA, NA, NA, 2.97, 2.95)
)
data
# Pad gaps of the left eye:
mutate(data,
pupil_left = pad_gaps(pupil_left, time, gap_minimum = 1, padding = 1)
)
# Example 2: Realistic data
gaps
# Pad gaps of the left eye:
gaps <- mutate(gaps,
pupil_left_new = pad_gaps(pupil_left, timestamp, gap_minimum = 10,
padding = 4)
)
# Restructure the data and plot the results to compare the pupil measurements
# before and after padding the gaps:
gaps %>%
rename(pupil_left_old = pupil_left) %>%
pivot_longer(
cols = c(pupil_left_old, pupil_left_new),
names_to = "status",
names_pattern = "(old|new)",
values_to = "pupil_size"
) %>%
ggplot(aes(x = timestamp, y = pupil_size, color = status)) +
geom_point()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.