dapply {emuR}R Documentation

apply a function to each part of a trackdata object

Description

Given an Emu trackdata object, dapply will apply a given function to the data corresponding to each segment of data. The result is a new trackdata object.

Usage

dapply(trackdata, fun, ...)

Arguments

trackdata

An Emu trackdata object

fun

A function taking a matrix of data and a vector of times and returning a list with components $data and $ftime.

...

Additional arguments to be passed to fun

Details

dapply can be used to apply an arbitrary function to trackdata extracted from an Emu database. It can be used for example to smooth the data (see dsmooth) or differentiate it (see ddiff).

Trackdata is made up of three components: a matrix of data $data, a matrix of indexes ($index) and a matrix of segment times ($ftime). The indexes contain the start and end rows for each segment in the trackdata, the time matrix contains the start and end times of each data segment.

The function fun supplied to dapply should take one matrix of data (corresponding to one segment) and a vector of two times being the start and end of the data. It should return a modified data matrix, which can have any number of rows or columns, and a new pair of start and end times. The new start and end times are necessary because the operation applied might shorten or interpolate the data and hence change the times corresponding to the first and last rows of data.

Value

An Emu trackdata object with components:

data

A matrix of data with all segments concatenated by row.

index

A two column matrix of the start and end rows for each segment

ftime

A two column matrix of the start and end times for each segment

See Also

dsmooth ddiff

Examples



data(dip)
## formant data of the first segment in segment list dip
fm <- dip.fdat[1]

testfun <- function(data, ftime, n) {
  ## return only the first n rows of data
  ## doesn't check to see if there really are n rows...
  newdata <- data[1:n,]
  ## calculate a new end time
  interval <- (ftime[2]-ftime[1])/nrow(data)
  ftime[2] <- ftime[1] + interval*n
  ## now return the required list 
  return( list( data=newdata, ftime=ftime ) )
}

fm.first3 <- dapply( fm, testfun, 3 )
fm.first10 <- dapply( fm, testfun, 10 )



[Package emuR version 2.5.0 Index]