View source: R/long-to-wide-converter.R
| long_to_wide_converter | R Documentation |
This conversion is helpful mostly for repeated measures design, where
removing NAs by participant can be a bit tedious.
long_to_wide_converter(
data,
x,
y,
subject.id = NULL,
paired = TRUE,
spread = TRUE,
...
)
data |
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from |
x |
The grouping (or independent) variable from |
y |
The response (or outcome or dependent) variable from |
subject.id |
Relevant in case of a repeated measures or within-subjects
design (i.e., |
paired |
Logical that decides whether the experimental design is
repeated measures/within-subjects or between-subjects. The default is
|
spread |
Logical that decides whether the data frame needs to be
converted from long/tidy to wide (default: |
... |
Currently ignored. |
A tibble with NAs removed while respecting the
between-or-within-subjects nature of the dataset: for paired designs, a
subject with a missing value in any condition is removed entirely, while
for unpaired designs only the rows with missing values are removed. Rows
are grouped by subject.id whenever it is supplied, so with
paired = FALSE and a subject.id, a missing value still removes every
row of that subject. The .rowid column contains the subject identifier
(or an internal row identifier).
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# for reproducibility
library(statsExpressions)
set.seed(123)
# repeated measures design
long_to_wide_converter(
bugs_long,
condition,
desire,
subject.id = subject,
paired = TRUE
)
# independent measures design
long_to_wide_converter(mtcars, cyl, wt, paired = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.