I have looked for such a long time, and haven't been able to figure out how to run Principal Component Analysis in R with the csv file I have. I continue to get this error:
Error in cov.wt(z) : 'x' must contain finite values only
all I have so far is
data <- read.csv("2014 07 24 Pct Chg Variables.csv")
pca <- princomp(data3, cor=T)
Error in cov.wt(z) : 'x' must contain finite values only
I have some ""
in my csv file, and have tried
data2 <- apply(data, 1, f1)
data3 <- as.numeric(data2)
where f1
is a function to apply the mean where the value is a blank.
princomp.default
cannot deal with NA
values:
USArrests[3,2] <- NA
princomp(USArrests, cor = TRUE)
#Error in cov.wt(z) : 'x' must contain finite values only
You need to handle NA
s:
princomp(na.omit(USArrests), cor = TRUE)
#works
Or use princomp.formula
:
princomp(~ ., data = USArrests, cor = TRUE)
#works too (by calling na.omit` per default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With