long_to_wide_converter: Converts dataframe from long/tidy to wide format with 'NA's...

Description Usage Arguments Value Examples

View source: R/long_to_wide_converter.R

Description

This conversion is helpful mostly for repeated measures design, where removing NAs by participant can be a bit tedious.

It does not make sense to spread the dataframe to wide format when the measure is not repeated, so if paired = TRUE, spread argument will be ignored.

Usage

1
2
3
4
5
6
7
8
9
long_to_wide_converter(
  data,
  x,
  y,
  subject.id = NULL,
  paired = TRUE,
  spread = TRUE,
  ...
)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. Other data types (e.g., matrix,table, array, etc.) will not be accepted.

x

The grouping (or independent) variable from the dataframe data. In case of a repeated measures or within-subjects design, if subject.id argument is not available or not explicitly specified, the function assumes that the data has already been sorted by such an id by the user and creates an internal identifier. So if your data is not sorted, the results can be inaccurate when there are more than two levels in x and there are NAs present. The data is expected to be sorted by user in subject-1,subject-2, ..., pattern.

y

The response (or outcome or dependent) variable from the dataframe data.

subject.id

Relevant in case of a repeated measures or within-subjects design (paired = TRUE, i.e.), it specifies the subject or repeated measures identifier. Important: Note that if this argument is NULL (which is the default), the function assumes that the data has already been sorted by such an id by the user and creates an internal identifier. So if your data is not sorted and you leave this argument unspecified, the results can be inaccurate when there are more than two levels in x and there are NAs present.

paired

Logical that decides whether the experimental design is repeated measures/within-subjects or between-subjects. The default is FALSE.

spread

Logical that decides whether the dataframe needs to be converted from long/tidy to wide (default: TRUE). Relevant only if paired = TRUE.

...

Currently ignored.

Value

A dataframe with NAs removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# for reproducibility
library(ipmisc)
set.seed(123)

# repeated measures design
long_to_wide_converter(
  data = bugs_long,
  x = condition,
  y = desire,
  subject.id = subject,
  paired = TRUE
)

# independent measures design (spread argument is ignored)
long_to_wide_converter(
  data = ggplot2::msleep,
  x = vore,
  y = brainwt,
  paired = FALSE,
  spread = FALSE
)

ipmisc documentation built on May 7, 2021, 9:07 a.m.