Question

In my lattice histogram:

histogram(~bill|group,data=mydat,type='count',nint=50,layout=c(9,3))

How to keep "bill" data before 99th percentile within each group?

Was it helpful?

Solution

You may want to remove outliers from the whole of the bill data. First copy your data into a new variable

    mydat$bill.cleaned=mydat$bill

then set the large values to missing

    cuttoff= qnorm(.99,mean(mydat$bill),sd(mydat$bill))
    mydat$bill.cleaned[which(mydat$bill > cuttoff)]=NA

Then you can display your histogram of cleaned data.

Alternatively if you want to remove ouliers only within each group. you need to do the same thing as above with an additional apply statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top