Skip to content

Commit

Permalink
Merge pull request #803 from easystats/pca_numericonly
Browse files Browse the repository at this point in the history
PCA: don't error when non-numerics are present
  • Loading branch information
strengejacke authored Oct 27, 2022
2 parents fdcc236 + 7956b74 commit bcc509d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/n_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ n_factors <- function(x,
nobs <- nrow(x)
}

# Get only numeric
x <- x[sapply(x, is.numeric)]

# Correlation matrix
if (is.null(cor)) {
cor <- stats::cor(x, use = "pairwise.complete.obs", ...)
Expand Down
3 changes: 3 additions & 0 deletions R/principal_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ principal_components.data.frame <- function(x,
# remove missing
x <- stats::na.omit(x)

# Select numeric only
x <- x[sapply(x, is.numeric)]

# N factors
n <- .get_n_factors(x, n = n, type = "PCA", rotation = rotation)

Expand Down

0 comments on commit bcc509d

Please sign in to comment.