Learn R Programming

emuR (version 2.5.0)

by.trackdata: A method of the generic function by for objects of class 'trackdata'

Description

A given function 'FUN' is applied to the data corresponding to each segment of data.

Usage

# S3 method for trackdata
by(data, INDICES = NULL, FUN, ..., simplify = FALSE)

Value

list or vector

Arguments

data

a track data object

INDICES

a list of segment indices, like a label vector

FUN

a function that is applied to each segment

...

arguments of the function fun

simplify

simplify = TRUE , output is a matrix; simplify = FALSE a list is returned

Author

Jonathan Harrington

Details

It is the same as trapply but with the extension to subsume calculation to groups of segments. Note, if you do not want to apply the function fun to a special group of segments, use trapply instead.

See Also

trapply, by, trackdata dapply smooth apply

Examples

Run this code

  data(demo.vowels)
  data(demo.vowels.fm)


   #mean F1 subsumed for each vowel
   ################################
   lab = label(demo.vowels)
   by(demo.vowels.fm[,1], lab ,sapply,mean,simplify=FALSE)


   #mean F1 subsumed for segment onsets mids and offsets
   ##############################################
   data = demo.vowels.fm
   llabs = NULL
   for (ind in 1:dim(data$ftime)[1]) {
     seglabs = rep("mid",data$index[ind,2]-data$index[ind,1]+1)
     seglabs[1] = "on"
     seglabs[length(seglabs)] = "off"
     llabs = as.vector(c(llabs , seglabs))
   }

   by(demo.vowels.fm[,1], llabs , sapply, mean , simplify=FALSE)

   #mean F1 subsumed for segment onsets mids and offsets subsumed for each vowel
   #####################################################################
   by(demo.vowels.fm[,1], list(lab = lab, llabs = llabs) , sapply, mean , simplify=FALSE)



Run the code above in your browser using DataLab