我正在使用心理包, 我试过以下代码:
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'**
>
如何成功进行因子分析? 首先我收到了错误消息,我的&#39; x&#39;必须是数字,这就是我使用上述代码的原因。 当我使用这段代码时,R告诉我,我通过转换得到了NA。 我仍然坚持并尝试fa.parallel,这给了我另一个错误信息。 有人可以帮忙吗?
答案 0 :(得分:0)
我不知道您是否已经解决了这个问题,但是如果您将字符数据与数字数据混合在一起(例如,您的编码是分类的,并且需要将其转换为数字,则可以尝试使用char2numeric函数,然后再使用做fa。
例如包含分类和数值混合数据;
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
似乎“最小吸引”对象中只有一个变量。