rwn1v
rwn1v

Reputation: 787

List Outliers per Variable in Dataframe

I have a data frame of 8 variables (x1, x2.. x8)

I would like to obtain the outliers of a boxplot using:

boxplot(dataframe, plot=FALSE)$out

My desired output is to have dataframe listing the outliers per variable. As follows:

variable outlier
x1       outlier1 from x1
x1       outlier2 from x1
x1       outlier3 from x1
x1       outlier4 from x1
x2       outlier1 from x2
x2       outlier2 from x2
x2       outlier3 from x2
.
.
.
x8       outliern from x8

Thanks for your support,

Upvotes: 0

Views: 219

Answers (1)

Joe
Joe

Reputation: 646

Is this what you want?

> testdata <- data.frame(x1=runif(1e3),x2=rnorm(1e3),x3=rnorm(1e3))
> temp <- boxplot(testdata,plot=F)
> cbind(temp$group,temp$out)
      [,1]      [,2]
 [1,]    2  2.765277
 [2,]    2  2.754730
 [3,]    2 -2.714811
 [4,]    2  3.257889
 [5,]    3  2.605549
 [6,]    3 -3.261950
 [7,]    3 -3.057532
 [8,]    3  2.820352
 [9,]    3  2.602933
[10,]    3  2.580897
[11,]    3  2.899350

Upvotes: 1

Related Questions