Home > OS >  In R package `factoextra` , using `get_dist`can calculate distance between variables,how to change t
In R package `factoextra` , using `get_dist`can calculate distance between variables,how to change t

Time:01-29

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()

CodePudding user response:

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))
  • Related