Learn R Programming

erp.easy (version 1.0.0)

dif.wave: Calculate a difference waveform from two data frames

Description

dif.wave calculates a difference waveform from two data frames in the format returned from load.data

Usage

dif.wave(x, z, name = NULL, keep = NULL)

Arguments

x
A data frame in the format returned from load.data. This value serves as the minuend (i.e., value to be subtracted from).
z
A data frame in the format returned from load.data. This value serves as the subtrahend (i.e., value subtracted).
name
Specify the Stimulus column name of the difference data frame. Must provide the new name in quotations.
keep
Include one of the data frames used in subtraction in the returned difference data frame. By default keep = NULL and only the resulting difference data frame will be returned.

Value

One of two possible data frames, depending on the value of keep:
  1. keep = "y": the difference (i.e., x - z) data frame and the minuend data frame (i.e., x)
  2. keep = "n": just the difference data frame

Details

The data frames must either:
  1. have been imported using load.data - OR -
  2. for subset data, the "Stimulus" column must be "refactored." See the example below for one way to "reset" the factors in the "Stimulus" column. Note this procedure is only necessary for subset data, and not data frames that were independently imported.

Examples

Run this code
# Calculate a difference wave
 Negative = ERPdata[1:6765, ]
 Neutral = ERPdata[6766:13530, ]
 refactor.neg <- factor(Negative$Stimulus)
 refactor.neut <- factor(Neutral$Stimulus)
 Negative$Stimulus <- refactor.neg
 Neutral$Stimulus <- refactor.neut
 difference <- dif.wave(Negative, Neutral, name = "Neg - Neut", keep = Neutral)
 head(difference) # view the new Stimulus column name
 grandaverage(difference, "V78") # plot the grand average difference wave

Run the code above in your browser using DataLab