首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cor(x,use = use)中出错:同时提供'x‘和'y’或类似矩阵的'x‘

cor(x,use = use)中出错:同时提供'x‘和'y’或类似矩阵的'x‘
EN

Stack Overflow用户
提问于 2018-05-29 23:41:44
回答 1查看 11.7K关注 0票数 0

我正在使用心理包,下面是我尝试过的代码:

代码语言:javascript
复制
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)

我收到以下错误消息:

代码语言:javascript
复制
 > 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,这给了我另一个错误消息。有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2018-09-24 03:56:07

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

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

代码语言:javascript
复制
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”对象中似乎只有一个变量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50588219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档