Learn R Programming

itsadug (version 1.0.1)

getCountData: Reducing fixations to count data.

Description

Function uses table with factors to count the occurrances of each value in the predictor.

Usage

getCountData(x, split_by, data = NULL, values = NULL, incl_na = FALSE)

Arguments

x
Name of a column in data or vector with values to be counted.
split_by
Vector with column names in data or named list with grouping predictors.
data
Optional: data frame.
values
Values of x that should be counted. If NULL (default) all values are counted.
incl_na
Logical: whether or not to return a count of missing values.

Value

  • A data frame with cbinded count information.

Note

Will be moved to other package.

See Also

table

Examples

Run this code
# simulate some gaze data:
dat <- data.frame(
 Subject = rep(1:3, 500),
 Timestamp = rep(1:500, 3),
 AOI = rep( rep( c('other','competitor', 'target'), 3),
 c(184, 172, 144, 51, 264, 185, 127, 2, 371)) )
# add missing data:
dat[sample(nrow(dat), size=15),]$AOI <- NA

# add timebins:
dat$Timebin <- timeBins(dat$Timestamp, 100)

# calculate counts:
c1 <- getCountData('AOI', data=dat, split_by=c('Subject', 'Timebin'))
head(c1)
# calculating proportions:
c1$prop <- c1$AOI[,'target'] / ( c1$AOI[,'competitor']+c1$AOI[,'other'])

# calculating counts for specific values, including missing data.
# Note that 'distractor' is not in the data:
c2 <- getCountData('AOI', data=dat, split_by=c('Subject', 'Timebin'),
values=c('target', 'distractor', 'competitor', 'other'), incl_na=TRUE)
head(c2)

Run the code above in your browser using DataLab