2

我有一个混合数据类型(整数、字符和逻辑)的数据框,我试图用菊花进行聚类。

我在用着:

gower_dist <- daisy(relchoice, metric = "gower")

并得到:

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

希望对此有所帮助。

4

1 回答 1

5

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

df$job <- as.factor(df$job)
于 2018-10-30T12:12:53.617 回答