get_stats_for_unique_values: Get stats for unique values

View source: R/operations.R

get_stats_for_unique_valuesR Documentation

Get stats for 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_stats_for_unique_values(vec1, vec2)

Arguments

vec1

vector with names attribute

vec2

vector with names attribute

Value

A data.frame consisting of 3 column vectors. The data.frame size is nx3, where n is the number of unique values of vec1 (rows). 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

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_stats_for_unique_values(vec1, vec2)


usefun documentation built on Sept. 17, 2023, 9:06 a.m.