ez.2long: reconstruct to long format, wrapper of 'reshape'

View source: R/frame.R

ez.2longR Documentation

reconstruct to long format, wrapper of reshape

Description

can handle one (similar to gather(), which does not require index input) or two repetitions

Usage

ez.2long(
  df,
  id,
  indexname,
  index,
  measurename = NULL,
  measure = NULL,
  drop = NULL,
  ...
)

Arguments

id

unique identification variable, or variable combination

indexname

variable name (column to be created) for timing/repetition/index variable, such as "session"

index

level name (value labels to be created) for each timing/repetition/index point, such as c("1,2"), c("Pre, Post")

measurename

variable name (column/columns to be created) for the measurement, such as "BDI"

measure

column names (existing) that are the repeated measures, such as c("BDI_Pre","BDI_Post")

drop

variables to drop before reshaping

Value

returns a new df, label attributes seem to be intact.

Note

refer to my spss syntax 'Time(2) | Measure1(Pre1 Post1) | Measure2(Pre2 Post2) +/- Subject'
if index=c("Pre","Post"), then the character would not be viewed by ez.vx; index=1:2 will be int and fine.

See Also

gather, spread, separate, unite
select, slice
distinct, arrange
summarise, count, mutate
group_by, left_join, right_join, inner_join, full_join, semi_join, anti_join
intersect, union, setdiff
bind_rows, bind_cols

Other data transformation functions: ez.2char(), ez.2factor(), ez.2label(), ez.2lower(), ez.2value(), ez.2wide(), ez.compute(), ez.del(), ez.label.get(), ez.label.set(), ez.labels.get(), ez.labels.set(), ez.move(), ez.newcol(), ez.num(), ez.recode(), ez.recols(), ez.recol(), ez.rename(), ez.replace(), ez.rncols(), ez.rncol(), ez.select(), ez.sort(), ez.split(), ez.str(), ez.unique(), left_join()

Examples

df <- data.frame(
    id = 1:10,
    time = as.Date('2009-01-01') + 0:9,
    Q3.2.1. = rnorm(10, 0, 1),
    Q3.2.2. = rnorm(10, 0, 1),
    Q3.2.3. = rnorm(10, 0, 1),
    Q3.3.1. = rnorm(10, 0, 1),
    Q3.3.2. = rnorm(10, 0, 1),
    Q3.3.3. = rnorm(10, 0, 1)
)
ez.2long(df, "id",
       "loop_number",c(1:3),
       c('Q3.2','Q3.3'),
       list(c("Q3.2.1.","Q3.2.2.","Q3.2.3."),c("Q3.3.1.","Q3.3.2.","Q3.3.3.")))

jerryzhujian9/ezmisc documentation built on March 9, 2024, 12:44 a.m.