Learn R Programming

schoRsch (version 1.2)

zscores: Compute z-Scores by Condition

Description

Data of an input vector is transformed to z-scores (mean = 0, sd = 1). The function operates on single vectors as well as on specified columns of a data frame.

Usage

zscores(data, factors=NaN, dv=NaN)

Arguments

data
Either a data frame containing the data of interest or a single vector.
factors
If called with factors=NaN (default), the entire data is processed according to its grand mean and total variance. If data is a vector, factors can be a list of variables for splitting the variable into separate compartments. If data is a data frame, factors has to be specified as a character vector of column names or column indices.
dv
If data is a single vector, dv does not have to be specified. If data is a data frame, dv indicates the column of the data frame which contains the variable for z-transformation (e.g., dv="rt") or its column index (e.g., dv=15).

Value

zscores() returns a vector containing the requested z-scores.

Details

zscores computes z-score of a vector or a specified column within a dataframe. Computation can be done separately for combinations of factors.

See Also

scale; split; outlier;

Examples

Run this code
# Create input vector and compute z-scores
measurements <- c(3,12,5,4,2,23,1,6)
zscores(measurements)

# Compute z-scores separately
# for conditions
cond1 <- c(1,1,1,1,2,2,2,2)
cond2 <- c(1,1,2,2,1,1,2,2)
zscores(measurements,list(cond1))
zscores(measurements,list(cond1,cond2))

# Calling zscores for data frames
data <- data.frame(measurements,
	cond1,cond2)
zscores(data,dv="measurements",
	factors=c("cond1","cond2"))
	
# Operating on column indices
zscores(data,dv=1,
	factors=3)

Run the code above in your browser using DataLab