我正在使用心理包,下面是我尝试过的代码:
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,这给了我另一个错误消息。有人能帮上忙吗?
发布于 2018-09-24 03:56:07
我不知道你是否已经解决了这个问题,但是如果你有混合了数字数据的字符数据(例如,你的编码是分类的,你需要将它转换成数字数据,你可以在执行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”对象中似乎只有一个变量。
https://stackoverflow.com/questions/50588219
复制相似问题