Calculating all possible differences of observations in R

45 Views Asked by At

I have the following data frame and

# Create a dummy dataframe
dummy_df <- data.frame(
  observation = as.factor(rep(1:4, each = 3)), # Factor from 1 to 4, repeated for each species
  species = rep(c("A", "B", "C"), times = 4),
  species_id = rep(c("A110", "B202", "C230","A110", "B2", "C26", "A09", "B45", "C23", "A11", "B20", "C235"), times = 4),# Species A, B, and C
  size = rep(c("a", "b"), each = 6), # Size classes a, b, and c
  measurement = runif(12, min = -2.3, max = -1) # Numeric measurement from -1 to -2.3
)

I want to build for every observation (a factor) and species (a factor) the difference between measurement. So I want to calculate always the measurement for size a - b for all combination of species_id with size a - species_id size j. In the end, a mean and standard error of these combinations of differences should be built.

0

There are 0 best solutions below