我有一个包含混合数据类型(整数、字符和逻辑)的数据框,我试图将其与 Daisy 聚类。
我正在使用:
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
希望得到一些帮助。
最佳答案
我能够通过将分类字段转换为因子数据类型来解决这个问题,例如:
df$job <- as.factor(df$job)
关于cluster-analysis - 使用 Daisy 获取 "invalid type character"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52522960/