rfactoextra

In R package `factoextra` , using `get_dist`can calculate distance between variables,how to change the result into data.frame format


In R package factoextra , using get_distcan calculate distance between variables,how to change the result into data.frame format ? Thanks! Below code return cannot coerce class ‘"dist"’ to a data.frame

library(factoextra)
data("USArrests")
res.dist <- get_dist(USArrests,stand = TRUE, method ="pearson")
res.dist %>% as.data.frame()

Solution

  • You have to use as.matrix first.

    Using pipes

    res.dist %>% as.matrix() %>% as.data.frame()
    

    Nested function calls

    as.data.frame(as.matrix(res.dist))