【发布时间】:2018-08-07 13:41:36
【问题描述】:
示例数据:
set.seed(1234)
a <- matrix(rnorm(250),nrow=25,ncol=10)
fac <- as.factor(c(rep("A",8),rep("B",10),rep("C",7)))
a.dist <- dist(a, "euclidian")
boxplot(a.dist ~ fac)
当我尝试运行 boxplot(a.dist ~ fac) 时,我收到以下错误:
Error in model.frame.default(formula = a.dist ~ fac) :
variable lengths differ (found for 'fac')
我试图解决这个问题
a.dist <- as.matrix(a.dist)
a.dist[upper.tri(a.dist)] <- NA
然后boxplot 给我回了一个有趣的情节。
我可以用
绘制特定组的组内欧几里得距离subset <- as.factor(fac) %in% ("A")
a.dist.A <- a.dist[subset]
boxplot(a.dist.A)
基本上我需要为每个因子水平执行此操作,然后将这些箱线图组合成一个。有什么简单的方法吗?
【问题讨论】:
标签: r plot distance boxplot euclidean-distance