Skip to content

Commit

Permalink
Merge pull request #5 from PPaccioretti/4-add-na-rows-to-kmspc-results
Browse files Browse the repository at this point in the history
Add NA rows to cluster results
  • Loading branch information
PPaccioretti authored Mar 21, 2024
2 parents ab39565 + 0265b9c commit da9ff9e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions R/kmspc.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ kmspc <- function(data,
if (sum(myNumVars) == 0) {
stop('Non numeric variables were found in data')
}
variables <- names(data)[myNumVars]
variables <- names(sf::st_drop_geometry(data))[myNumVars]
}

if (!inherits(data, "sf") & (length(variables) > 1)) {
Expand All @@ -58,6 +58,12 @@ kmspc <- function(data,
}

data <- data[, variables]
raw_nrow <- nrow(data)
myNArows <- apply(sf::st_drop_geometry(data), 1, function(x) {
any(is.na(x))
})


data <- stats::na.omit(data)
data_clust <- data
if (ncol(sf::st_drop_geometry(data)) > 1 ) {
Expand Down Expand Up @@ -109,10 +115,20 @@ kmspc <- function(data,
if (inherits(data_clust, "sf")) {
data_clust <- sf::st_drop_geometry(data_clust)
}
make_clasification(data_clust,
number_cluster,
fuzzyness = fuzzyness,
distance = distance)
my_results <- make_clasification(data_clust,
number_cluster,
fuzzyness = fuzzyness,
distance = distance)


cluster_na <- data.frame(matrix(NA,
nrow = raw_nrow,
ncol = ncol(my_results$cluster)))
colnames(cluster_na) <- colnames(my_results$cluster)
cluster_na[!myNArows, ] <- my_results$cluster

my_results$cluster <- cluster_na
my_results

}

Expand Down

0 comments on commit da9ff9e

Please sign in to comment.