在此操作中,x
为tbl_df
,outliers
为data.frame
。
但是id
会返回logical
,而不是tbl_df
。
我做错了什么?
x <- as_tibble(c(rep(2,10),50,64,80))
boxplot1 <-
ggplot (data=x, aes_string (x = factor(0), y = "x" )) +
geom_boxplot (fill = "lightgreen", outlier.fill = "darkgreen") +
stat_boxplot(geom ='errorbar', color = "grey") +
coord_flip () +
ggtitle (paste0 ("x", ", with outliers"))
outliers <- data.frame (unlist (ggplot_build(boxplot1)$data[[1]][6],use.names = F),stringsAsFactors=FALSE)
id <- x %in% outliers
我期望一个长度与x相同的tbl_df。实际上,id&lt; - match(outliers,x)返回长度异常值的数字,但id&lt; - match(x,outliers)不返回长度为x的数字
答案 0 :(得分:0)
解决方案是id
置于问题id <- x[[1]] %in% outliers[[1]]
,但我不明白为什么。