compute gower distance without using method = "gower", given a dataset of mixed data

`gower_dist <- function(data) { # gower_dist <- function() { df <- data num_rows <- nrow(df) num_cols <- ncol(df) dist <- matrix(0, nrow=num_rows, ncol=num_rows) for (i in 1:num_cols) { if (is.numeric(df[,i])) { dist <- dist + ((df[,i]-t(df[,i]))^2)/var(df[,i]) } else if (is.ordered(df[,i]) || is.factor(df[,i])) { dist <- dist + (abs(df[,i]-t(df[,i])))/(max(df[,i],na.rm = TRUE)-min(df[,i],na.rm = TRUE)) } else { dist <- dist + (df[,i] != t(df[,i])) } } return (dist)`