cytomining/cytominer

When aggregating a single variable using two or more functions, variable name is not preserved

shntnu opened this issue · 1 comments

cytominer::aggregate(iris, c("Sepal.Width"), c("Species"), operation = "mean")
#> # A tibble: 3 x 2
#>      Species Sepal.Width
#>       <fctr>       <dbl>
#> 1     setosa       3.428
#> 2 versicolor       2.770
#> 3  virginica       2.974
cytominer::aggregate(iris, c("Sepal.Width"), c("Species"), operation = "mean+sd")
#> # A tibble: 3 x 3
#>      Species  mean        sd
#>       <fctr> <dbl>     <dbl>
#> 1     setosa 3.428 0.3790644
#> 2 versicolor 2.770 0.3137983
#> 3  virginica 2.974 0.3224966
cytominer::aggregate(iris, c("Sepal.Width", "Sepal.Length"), c("Species"), operation = "mean+sd")
#> # A tibble: 3 x 5
#>      Species Sepal.Width_mean Sepal.Length_mean Sepal.Width_sd
#>       <fctr>            <dbl>             <dbl>          <dbl>
#> 1     setosa            3.428             5.006      0.3790644
#> 2 versicolor            2.770             5.936      0.3137983
#> 3  virginica            2.974             6.588      0.3224966
#> # ... with 1 more variables: Sepal.Length_sd <dbl>

It's probably best to preserve the behavior of summarize, which is to drop the column name. We might need to revisit depending on the use cases for this.