Description Usage Arguments Examples
View source: R/invalid_to_na.R
invalid_to_na
sets invalid pupil measurements to missing (NA).
1 | invalid_to_na(pupil, condition)
|
pupil |
A numeric vector containing pupil data. |
condition |
A condition to determine which values should be set to NA. |
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 41 | # Example 1: Artificial vector
# Set the value '4' to missing in a vector from '1' to '10':
invalid_to_na(1:10, 1:10 == 4)
# Example 2: Artificial data
# Load the "dplyr" package:
library(dplyr)
# Create some artificial data:
data <- tibble(
pupil_left = c(3.15, 3.14, 3.13, -1, -1, 3.11),
pupil_right = c(2.92, 2.89, 2.93, -1, -1, 2.97),
validity_left = c(0, 0, 0, 4, 4, 0),
validity_right = c(0, 0, 0, 4, 4, 0)
)
data
# Set all pupil sizes with a value of -1 to NA:
mutate(data,
pupil_left = invalid_to_na(pupil_left, pupil_left == -1),
pupil_right = invalid_to_na(pupil_right, pupil_right == -1)
)
# Or, set pupil sizes to NA based on values in the validity columns:
mutate(data,
pupil_left = invalid_to_na(pupil_left, validity_left == 4),
pupil_right = invalid_to_na(pupil_right, validity_right == 4)
)
# Example 3: Realistic data
# Inspect data:
trial1
count(trial1, validity_left, validity_right)
slice(trial1, 100:115)
# Set invalid pupil observations of the left eye to NA:
trial1 <- mutate(trial1, pupil_left = invalid_to_na(pupil_left,
validity_left == 4))
# Inspect the data frame again to see whether it worked:
slice(trial1, 100:115)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.