data.table - how to find outliers in multiple rows when the first column is in id form in R -
i have data looks this
mem_id age1 age2 age3 age4 age5 age6 age7 age8 age9 age10 1 3 5 5 6 7 8 9 10 11 15 2 5 6 7 8 10 10 11 11 12 13 3 7 7 7 7 8 8 8 9 9 9 4 8 8 8 8 8 8 9 9 9 9 5 12 13 14 9 15 16 16 16 16 16
i want find out outliers in each row using criteria value of element in row particular mem_id
not in range of q1-1.5*inter quartile range,q3-1.5*inter quartile range q1 first quartile , q3 third quartile classify has outlier
so want output
mem_id outliers 1 age2 3, age1 5 2 age3 6,age4 7
that output tell me location of outliers , value of outliers each mem_id.
probably not after (though bit confused still output should like) code create true / false grid outlying values have true value , in-lying values have false value
x <- c (1 , 3 , 5 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 15, 2 , 5 , 6 , 7 , 8 , 10 ,10 , 11 , 11 , 12 ,13, 3 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9, 4 , 8 , 8 , 8 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 5 , 12 , 13 , 14 , 9 , 15 ,16 , 16 , 16 , 16 ,16) mat <- matrix(x , byrow = t , ncol = 11) mat2 <- mat[ ,-1 ] <- apply( mat2 , 1 , iqr) m <- apply( mat2 , 1 , mean ) upper <- sweep(mat2 , 1 , m + 1.5* , ">") lower <- sweep(mat2 , 1 , m - 1.5* , "<") (outlie <- upper | lower)
Comments
Post a Comment