elements | R Documentation |
Extract the unique elements from a term or variable in their natural order. For categorical variables (factors), this returns the factor levels. For continuous variables, this returns the unique values in ascending order. For event terms with multiple variables, this returns the combined elements.
elements(x, ...)
## S3 method for class 'event'
elements(x, what = c("values", "labels"), transformed = TRUE, ...)
## S3 method for class 'event_term'
elements(x, what = c("values", "labels"), ...)
x |
The term or variable object (typically an event_term, event_factor, or event_variable) |
... |
Additional arguments passed to methods |
what |
Character; what to extract - "unique" for unique values or "all" for all values (default: "unique") |
transformed |
Logical; if TRUE, return transformed values (default: FALSE) |
Return the ordered elements of a term or variable.
A vector containing the ordered elements:
For factors: The factor levels in their defined order
For numeric variables: Unique values in ascending order
For event terms: Combined elements from all variables
levels()
, event_term()
# Create event terms with different types
# Categorical variable
event_data <- data.frame(
condition = factor(c("A", "B", "A", "B"), levels = c("B", "A")),
onsets = c(1, 10, 20, 30),
run = c(1, 1, 1, 1)
)
cat_term <- event_term(
list(condition = event_data$condition),
onsets = event_data$onsets,
blockids = event_data$run
)
elements(cat_term) # Returns: c("B", "A")
# Continuous variable
event_data$rt <- c(1.2, 0.8, 1.1, 0.9)
cont_term <- event_term(
list(rt = event_data$rt),
onsets = event_data$onsets,
blockids = event_data$run
)
elements(cont_term) # Returns: c(0.8, 0.9, 1.1, 1.2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.