Learn R Programming

erpR (version 0.2.0)

rearrange: rearrange a data frame from wide to long format

Description

This utility function of the erpR package converts an ERP data frame with a single variable in wide format to a long format.

Usage

rearrange(deps, oth = NULL, dataset, name.dep = "Dep", name.newvar = "New_Var")

Arguments

deps
the numbers of the columns in the specified data frame to be rearranged from wide format to long format.
oth
other variables that are to be kept in the returned data frame.
dataset
the name of the data frame to be converted from wide format to long format.
name.dep
the name of the dependent variable in the returned data frame.
name.newvar
the name of the variable indicating the levels associated with name.dep in the returned data frame.

Value

A data frame in which the variables specified in the columns deps are converted in a single column name.dep with levels specified in name.newvar

Details

The function converts a dataframe with a single variable in wide format (levels are in separate columns) in a data frame in long format (the variable is in a single column and the levels are specified by other columns). The original variable in wide format is represented in two columns: one (labeled by name.dep parameter) indicating the values of the dependent variable, and the other that is a factor (labeled by name.newvar parameter) indicating the levels of the variable for each observation. The variables specified in oth are replicated appropriately. This function is called internally by erp.mean, erp.peak, and erp.latency.

See Also

erp.mean, erp.peak, erp.latency

Examples

Run this code

data(ERPsets)

datwide=erp.mean(base="Exp1_word_subj", numbers=1:20, win.ini=130, 
win.end=190, erplist=ERPsets, startmsec=-200, endmsec=1500, format="wide")

dat.long=rearrange(deps=c(1:32), oth=33:34, dataset=datwide, name.newvar="electrode")


Run the code above in your browser using DataLab