Learn R Programming

usefun (version 0.4.1)

get_average_over_unique_values: Get average over unique values

Description

Use this function on two vectors with same names attribute (column names), to find for each unique (numeric) value of the first vector, the average and standard deviation values of the second vector's values (matching is done by column name)

Usage

get_average_over_unique_values(vec1, vec2)

Arguments

vec1

vector with names attribute

vec2

vector with names attribute

Value

A matrix consisting of 3 column vectors. The matrix size is dim(matrix)= 3xn, where n is the number of unique values of vec1). The columns vectors are:

  1. the first input vector pruned to its unique values

  2. a vector with the average values for each unique value of the first vector (the matching is done by column name)

  3. a vector with the standard deviation values for each unique value of the first vector (the matching is done by column name)

Examples

Run this code
# NOT RUN {
vec1 = c(1, 2, 3, 2)
vec2 = c(20, 2, 2.5, 8)
names.vec = c(seq(1,4))
names(vec1) = names.vec
names(vec2) = names.vec

res = get_average_over_unique_values(vec1, vec2)

# }

Run the code above in your browser using DataLab