Reputation: 21
I am new to R and trying to run a factor analysis (method = pca. rotation = varimax and number of factors is 6). I've a survey data that I loaded to R, and then selected a subset of cases, and variables. I did the following:
arab<-read.table("C:\\Users\\admin\\Desktop\\spsapaper\\arabb.csv",header=T,sep=",")
abjor<-subset(arab,COUNTRY=="1")
items<- c("Q2011", "Q2012", "Q4012", "Q4013", "Q5022", "Q5051", "Q5052", "Q5056", "Q5055", "Q6131", "Q6133", "Q6132", "Q2464", "Q2462", "Q2013", "Q2473", "Q2476", "Q2475", "Q2014", "Q5022", "Q2323")
install.packages("psych")
library(psych)
So far everything ran smoothly, and I used the fix() function to check the data in the editor and it worked. Then I ran:
fit <- factanal(abjor, 6, rotation="varimax")
and it gave me:
Error in cov.wt(z) : 'x' must contain finite values only
I tried to fix the problem by deleting missing values via:
abjorr<- na.omit(abjor)
and it gave me
Error in factanal(abjorr, 6, rotation = "varimax") :
factor analysis applies only to numerical variables
The fix()
produced an empty data editor with no values.
Then, I tried, nabjor<- v[ !is.na( abjor ) ]
and ran fix()
and it produced a data editor with all NA
values.
I'm trying to handle missing values to run a factor analysis, but it seems that I'm missing something?
Upvotes: 2
Views: 3025
Reputation: 12654
How about:
abjor2<-complete.cases(abjor)
The complete.cases
function will give you only those rows that do not have any NA values.
Upvotes: 1