I want to find the index of the outlier spotted by the grubbs.test
function of the outliers
package (I adapted it from another SO answer here)
where = function(x) which(x==as.numeric(strsplit(grubbs.test(x)$alternative," ")[[1]][3]))
It works by retrieving the number in the text displayed by the grubbs result. It's kind of a hack but it works well, let's say, for round numbers:
df=c(0, 3, rnorm(10))
where(df) #[1] 2
When it gets to decimal numbers, the text doesn't match all the times with the digits of the actual number:
df=c(0, sqrt(10), rnorm(10))
where(df) # integer(0)
Someone has an idea to fix that problem? Or another way to find the index of the grubbs test biggest outlier? I'm trying to use this in a loop.