如何检测向量中的异常值?
例如,我有以下向量
color<-c("green","green","green","green","green","red","blue")
size<-c("big","small","big","big","big","small","medium")
对于每个矢量我想检测异常值并绘制热图
color
异常值位于第6和第7位size
异常值位于2,6,7 答案 0 :(得分:0)
像
这样的东西color <- c("green","green","green","green","green","red","blue")
tt <- table(color)
names(tt)[tt<2] ## values with frequency < 2
## 'blue', 'red'
ptt <- prop.table(tt)
names(ptt)[ptt<0.2] ## values with frequency < 20%
## 'blue', 'red'