Skip to content

rearrange(absolute = TRUE) doesn't do anything #167

@jmbarbone

Description

@jmbarbone

The problem

abs(m) isn't assigned?

corrr/R/cor_df.R

Lines 39 to 46 in bd5841d

rearrange.cor_df <- function(x, method = "PCA", absolute = TRUE) {
# Convert to original matrix
m <- as_matrix(x, diagonal = 1)
if (absolute) abs(m)
if (method %in% c("BEA", "BEA_TSP", "PCA", "PCA_angle")) {

Reproducible example

library(corrr)
df <- data.frame(
  x = 1:10,
  y = -c(1:10),
  z = 1:10
)

cdf <- correlate(df)
#> Correlation computed with
#> • Method: 'pearson'
#> • Missing treated using: 'pairwise.complete.obs'
rearrange(cdf, absolute = TRUE)  # shouldn't change order
#> # A tibble: 3 × 4
#>   term      x     z     y
#>   <chr> <dbl> <dbl> <dbl>
#> 1 x        NA     1    -1
#> 2 z         1    NA    -1
#> 3 y        -1    -1    NA
rearrange(cdf, absolute = FALSE) # expected (because not assigned)
#> # A tibble: 3 × 4
#>   term      x     z     y
#>   <chr> <dbl> <dbl> <dbl>
#> 1 x        NA     1    -1
#> 2 z         1    NA    -1
#> 3 y        -1    -1    NA
cdf[2:4] <- lapply(cdf[2:4], abs)
rearrange(cdf)
#> # A tibble: 3 × 4
#>   term      x     y     z
#>   <chr> <dbl> <dbl> <dbl>
#> 1 x        NA     1     1
#> 2 y         1    NA     1
#> 3 z         1     1    NA

Created on 2022-12-13 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions