'Error in cor(x, use = use) : supply both 'x' and 'y' or a matrix-like 'x'

I am using the psych package, following code I tried:

library(psych)
str(price_per_d)
Least_appealing <-subset(zdf_base, select=c("price_per_h", 
"price_per_d", "mileage", "one_way_option", "difficulties", 
"vehicle_types", "parking_spot","picking_up","availability", "dirty", 
"returning","refilling", "loalty_programs"))
# code from stackoverflow which I use, to get a numeric x
Least_appealing <- gsub(",", "", Least_appealing)  
Least_appealing <- as.numeric(Least_appealing)

fa.parallel(Least_appealing)

I get this error messages:

 > library(psych)
 > str(price_per_d)
 Factor w/ 1 level "Price (daily rate too high)": 1 NA 1 1 1 NA NA 1 1 
 NA ...
 > Least_appealing <-subset(zdf_base, select=c("price_per_h", 
 +                                             "price_per_d", 
 "mileage", "one_way_option", "difficulties", 
 +                                             "vehicle_types", 
 "parking_spot","picking_up","availability", "dirty", 
 +                                             "returning","refilling", 
 "loalty_programs"))
 > 
 > Least_appealing <- gsub(",", "", Least_appealing)  
 > Least_appealing <- as.numeric(Least_appealing)
 **Warnmeldung:
 NAs durch Umwandlung erzeugt** 
> 
> fa.parallel(Least_appealing)
**Fehler in cor(x, use = use) : supply both 'x' and 'y' or a matrix-like 
'x'**
> 

How can I conduct a Factor analysis succesfully?

First I got the error message, my 'x' must be numeric, that's why I used the above mentioned code.

When I used this code, R tells me, that I got NA's through the conversion. I still kept on and tried fa.parallel, which gives me another error message.



Solution 1:[1]

If you have character data intermixed with numeric data (e.g., your coding is categorical and you need to convert it to numerical, you could try using the char2numeric function before doing the fa.

e.g. with data that are a mix of categorical and numerical;

describe(data)  #this will flag those variables that are categorical with an asterix
new.data <- char2numeric(data)  #this makes all numeric
fa(new.data, nfactors=3) #to get three factors

It appears that you have only one variable in your 'least.appealing' object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TylerH