%in%不返回原子结果

时间:2017-07-06 12:53:11

标签: r dplyr

在此操作中,xtbl_dfoutliersdata.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的数字

1 个答案:

答案 0 :(得分:0)

解决方案是id置于问题id <- x[[1]] %in% outliers[[1]],但我不明白为什么。