daisy 出现“无效类型字符”错误

Gil*_*des 4 cluster-analysis r-daisy

我有一个包含混合数据类型(整数、字符和逻辑)的数据框,我试图将其与 daisy 进行聚类。

我在用着:

gower_dist <- daisy(relchoice, metric = "gower")
Run Code Online (Sandbox Code Playgroud)

并得到:

Error in daisy(relchoice, metric = "gower") : 
invalid type character for column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 
21, 29, 31, 32invalid type character for column numbers 3, 4, 5, 7, 8, 10, 
13, 14, 15, 16, 21, 29, 31, 32invalid type character for column numbers 3, 
4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 32invalid type character for 
column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 32invalid type 
character for column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 
32invalid type character for column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 
16, 21, 29, 31, 32invalid type character for column numbers 3, 4, 5, 7, 8, 
10, 13, 14, 15, 16, 21, 29, 31, 32invalid type character for column numbers 
3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 32invalid type character for 
column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 32invalid type 
character for column numbers 3, 4, 5, 7, 8, 10, 13, 14, 15, 16, 21, 29, 31, 
32
Run Code Online (Sandbox Code Playgroud)

希望得到一些帮助。

Tom*_*mas 7

我能够通过将分类字段转换为因子数据类型来解决这个问题,例如:

df$job <- as.factor(df$job)
Run Code Online (Sandbox Code Playgroud)