0

我正在使用 psych 包,我尝试了以下代码:

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)

我收到此错误消息:

 > 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'**
> 

如何成功进行因子分析?首先我收到错误消息,我的“x”必须是数字,这就是我使用上述代码的原因。当我使用这段代码时,R 告诉我,我通过转换得到了 NA。我仍然继续尝试 fa.parallel,它给了我另一个错误消息。任何人都可以帮忙吗?

4

1 回答 1

0

我不知道你是否已经解决了这个问题,但是如果你有字符数据与数字数据混合(例如,你的编码是分类的并且你需要将它转换为数字,你可以在执行 fa 之前尝试使用 char2numeric 函数.

例如,使用分类和数字混合的数据;

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

您的“least.appealing”对象中似乎只有一个变量。

于 2018-09-23T19:56:06.830 回答