Learn R Programming

PredTest (version 0.1.0)

create_difference_vector: Create a Difference Vector

Description

This function calculates the difference between two groups of data based on a specified location measure (median or mean).

Usage

create_difference_vector(grp_1_data, grp_2_data, location = "median")

Value

A numeric vector representing the differences between the second group's location measure and the first group's location measure for each column.

Arguments

grp_1_data

A data frame where all columns are numeric, representing the first group of data.

grp_2_data

A data frame where all columns are numeric, representing the second group of data.

location

A string specifying the location measure to use for calculating differences. Must be either 'median' or 'mean'.

Details

The function checks if the specified location measure is valid ('median' or 'mean'). It also checks if both groups of data are numeric and if they have the same size and column variables. Based on the location measure, it calculates the differences and returns them as a numeric vector.

Examples

Run this code
df_1 <- data.frame(v1 = c(1, 2, 100),v2 = c(4, 5, 6))
df_2 <- data.frame(v1 = c(7, 6, 5),v2 = c(4, 3, 2))

create_difference_vector(df_2, df_1, 'median')
create_difference_vector(df_2, df_1, 'mean')

Run the code above in your browser using DataLab