将异常值输出到 R 中的向量或数据框中

问题描述 投票:0回答:0

在可爱的 Rui Barradas 的帮助下,我能够循环浏览多个列并创建带有标记异常值的箱线图。目前,我正在尝试使用以下代码将这些异常值输出到向量中:

ClusterRepVector <- character()
i_num = which(sapply(tpose_genexp, is.numeric)) #
str(tpose_genexp[i_num])
i_num <- i_num[c(1, 4, 5)]


lapply(names(tpose_genexp[i_num]), \(x) {
  bp <- boxplot(tpose_genexp[[x]], 
                horizontal = FALSE, # Horizontal or vertical plot
                lwd = 2, # Lines width
                col = rgb(1, 0, 0, alpha = 0.4), # Color
                main = x,
                notch = TRUE, 
                border = "black",
                outpch = 25,       # Outliers symbol
                outbg = "green",   # Outliers color
                whiskcol = "blue", # Whisker color
                whisklty = 2,      # Whisker line type
                lty = 1 )           # Line type (box and median)
  i_row = which(tpose_genexp[[x]] %in% bp$out)
  labs = if(length(i_row)) {
    tapply(row.names(tpose_genexp)[i_row], bp$out, paste, collapse = ", ")
  } else ""
  text(1.1, unique(bp$out), labels = labs, pos = 4)
outliername = c(row.names(tpose_genexp)[i_row])
ClusterRepVector = c(ClusterRepVector, outliername)
})

我遇到的问题是,我正在尝试的所有内容都会返回,并且空向量会在控制台中打印出异常值……所以我不明白为什么它不保存它。 console screenshot

r if-statement boxplot
© www.soinside.com 2019 - 2024. All rights reserved.