aggregate
aggregates data based on the specified aggregation method.
aggregate( population, variables, strata, operation = "mean", univariate = TRUE, ... )
population | tbl with grouping (metadata) and observation variables. |
---|---|
variables | character vector specifying observation variables. |
strata | character vector specifying grouping variables for aggregation. |
operation | optional character string specifying method for aggregation,
e.g. |
univariate | boolean specifying whether the aggregation function is univariate or multivariate. |
... | optional arguments passed to aggregation operation |
aggregated data of the same class as population
.
population <- tibble::tibble( Metadata_group = c( "control", "control", "control", "control", "experiment", "experiment", "experiment", "experiment" ), Metadata_batch = c("a", "a", "b", "b", "a", "a", "b", "b"), Area = c(10, 12, 15, 16, 8, 8, 7, 7), Intensity = c(3, -3, 35, -3, 3, 0, 9, -7) ) variables <- c("Area", "Intensity") strata <- c("Metadata_group", "Metadata_batch") aggregate(population, variables, strata, operation = "mean")#> # A tibble: 4 x 4 #> Metadata_group Metadata_batch Area Intensity #> <chr> <chr> <dbl> <dbl> #> 1 control a 11 0 #> 2 control b 15.5 16 #> 3 experiment a 8 1.5 #> 4 experiment b 7 1aggregate(population, variables, strata, operation = "mean+sd")#> # A tibble: 4 x 6 #> Metadata_group Metadata_batch Area_mean Intensity_mean Area_sd Intensity_sd #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 control a 11 0 1.41 4.24 #> 2 control b 15.5 16 0.707 26.9 #> 3 experiment a 8 1.5 0 2.12 #> 4 experiment b 7 1 0 11.3aggregate(population, variables, strata, operation = "median")#> # A tibble: 4 x 4 #> Metadata_group Metadata_batch Area Intensity #> <chr> <chr> <dbl> <dbl> #> 1 control a 11 0 #> 2 control b 15.5 16 #> 3 experiment a 8 1.5 #> 4 experiment b 7 1aggregate(population, variables, strata, operation = "covariance", univariate = FALSE)#> # A tibble: 4 x 5 #> Metadata_group Metadata_batch Area__Area Intensity__Area Intensity__Intensity #> <chr> <chr> <dbl> <dbl> <dbl> #> 1 control a 2 -6 18 #> 2 control b 0.5 -19 722 #> 3 experiment a 0 0 4.5 #> 4 experiment b 0 0 128