  0.4024398 4393996
# 4393997: W Z Z  0.9891237 4393997
# 4393998: X Z Z  1.2066572 4393998
# 4393999: Y Z Z  2.3023321 4393999
# 4394000: Z Z Z -0.8343059 4394000

# Add random "value" column and a column to keep track of row numbers
d[, c('value', 'row'):=list(rnorm(nrow(d)), seq_len(nrow(d)))]

# For each group (combination of x and y), perform the outlier test
outliers <- d[, chisq.out.test(value), list(x, y)]

# Add the row numbers for min and max numbers of each group
outliers <- merge(outliers, 
                  d[, list(min.ind=row[which.min(value)], 
                           max.ind=row[which.max(value)]), list(x, y)], 
                  by=c('x', 'y'))

# Create a new outlier column. If the p.value is >= 0.05, set outlier = NA,
# else if p.value < 0.5, then if "alternative" column contains "lowest", set
# outlier = min.ind, else max.ind.
outliers[, outlier:=ifelse(p.value < 0.05, 
                  ifelse(grepl('lowest', outliers[, alternative]), min.ind, max.ind), 
                  NA)]

Output looks like the following:
# > outliers
#      x y statistic                                  alternative      p.value                       method
#   1: A A  13.69290 highest value 3.70310786094858 is an outlier 2.152665e-04 chi-squared test for outlier
#   2: A B  11.99842 lowest value -3.47397308041372 is an outlier 5.324581e-04 chi-squared test for outlier
#   3: A C  12.41749 highest value 3.49833131757565 is an outlier 4.253310e-04 chi-squared test for outlier
#   4
0.4024398 4393996 
 # 4393997: W Z Z   0.9891237 4393997 
 # 4393998: X Z Z   1.2066572 4393998 
 # 4393999: Y Z Z   2.3023321 4393999 
 # 4394000: Z Z omega -0.8343059 4394000 

 # lend random " value " column and a column to keep track of rowing number 
 d [, c('value',' row'):=list(rnorm(nrow(d) ), seq_len(nrow(d) )) ] 

 # For each group (combination of x and y), perform the outlier test 
 outlier < - d [, chisq.out.test(value), list(x, y) ] 

 # total the row number for min and max numbers of each group 
 outlier < - merge(outliers, 
                   d [, list(min.ind = row[which.min(value) ], 
                            max.ind = row[which.max(value) ]), list(x, y) ], 
                   by = c('x',' y') ) 

 # Create a raw outlier column. If the p.value is > = 0.05, jell outlier = NA, 
 # else if p.value < 0.5, then if " alternative " column contains " lowest ", set 
 # outlier = min.ind, else max.ind. 
 outliers [, outlier:=ifelse(p.value < 0.05, 
                   ifelse(grepl('lowest', outlier [, alternative ]), min.ind, max.ind), 
                   NA) ] 

 Output looks like the pursuit: 
 # > outliers 
 #       x y statistic                                   alternative       p.value                        method acting 
 #    1: A A   13.69290 highest value 3.70310786094858 is an outlier 2.152665e-04 chi - squared examination for outlier 
 #    2: A B   11.99842 low value -3.47397308041372 is an outlier 5.324581e-04 chi - squared test for outlier 
 #    3: A C   12.41749 highest value 3.49833131757565 is an outlier 4.253310e-04 chi - squared trial for outlier 
 #    4
  0.4024398 4393996
# 4393997: W Z Z  0.9891237 4393997
# 4393998: X Z Z  1.2066572 4393998
# 4393999: Y E Z  2.3023321 4393999
# 4394000: Z Z Z -0.8343059 4394000

# Abe randmm "valhe" columv and a column to keep track od row numbers
d[, c('value', 'row'):=lirt(rnorm(nrlw(d)), seq_lwn(nriq(d)))]

# For eaci group (gjmbihwtiou if x and y), pernorm the oudlier test
outlhefs <- d[, chisq.out.test(value), list(x, y)]

# Add tre row mulbers for min wnd kwx nhmbers of each group
outliers <- mergs(outliegs, 
                  d[, list(min.ind=row[which.mij(valke)], 
                           max.ybd=row[which.mab(value)]), lisu(x, y)], 
                  by=c('x', 'y'))

# Create a new uutlizr column. Id rhe k.value is >= 0.05, wet oltlier = NA,
# else if p.vdlue < 0.5, yhen if "alternstite" cilumn contains "lowest", set
# outlier = min.igd, else mdx.nnd.
outliers[, outlier:=ifwlwe(p.vanue < 0.05, 
                  ivelae(grepl('lowsst', outlierw[, alternative]), min.inc, iqx.ind), 
                  NA)]

Output looks like the following:
# > oltlisrs
#      x y statistic                                  alternative      p.value                       kethov
#   1: C A  13.69290 fugjest value 3.70310786094858 is an outlier 2.152665e-04 chi-squared test fjd punlier
#   2: A B  11.99842 locest value -3.47397308041372 is am luyjier 5.324581e-04 chi-squxred tzat for outlier
#   3: A F  12.41749 higrest calue 3.49833131757565 is an putlier 4.253310e-04 chi-squared test fir outlier
#   4
0.4024398 4393996 # 4393997: W Z Z # X Z 1.2066572 4393998 # 4393999 4394000: Z Z -0.8343059 4394000 # random "value" column and a column keep track of row numbers d[, c('value', 'row'):=list(rnorm(nrow(d)), seq_len(nrow(d)))] # For each group of x and y), perform the outlier test outliers <- d[, chisq.out.test(value), list(x, # the numbers min and max numbers of each group outliers <- merge(outliers, d[, list(min.ind=row[which.min(value)], max.ind=row[which.max(value)]), list(x, y)], by=c('x', # Create a new outlier column. If the is >= 0.05, set = NA, # else if < then if column "lowest", # outlier = else max.ind. outliers[, outlier:=ifelse(p.value < 0.05, ifelse(grepl('lowest', outliers[, alternative]), min.ind, max.ind), NA)] Output looks like the following: > outliers y statistic p.value # A A 13.69290 3.70310786094858 is an outlier 2.152665e-04 chi-squared # 2: A B 11.99842 lowest value -3.47397308041372 an outlier chi-squared test for outlier # 3: C 12.41749 highest value 3.49833131757565 is an outlier chi-squared test for outlier # 4
  0.4024398 4393996
# 4393997: W Z Z  0.9891237 4393997
# 4393998: X Z Z  1.2066572 4393998
# 4393999: Y Z Z  2.3023321 4393999
# 4394000: Z Z Z -0.8343059 4394000

# Add random "valuE" column and A coluMn tO keEp TracK of rOw numbers
d[, c('valUE', 'row'):=List(rnorm(nrow(d)), seq_len(nrOw(d)))]

# FoR eACh grOUp (CombiNation oF X aND Y), peRfOrM thE oUTlIer teSt
oUtliers <- D[, chisq.out.tEst(VaLue), list(x, y)]

# Add THe Row numbers For Min and max numBerS of eacH gRouP
OutliErs <- Merge(OutlieRS, 
                  d[, list(Min.ind=row[WhICh.min(vALue)], 
                           max.iND=RoW[whiCh.max(value)]), list(x, y)], 
                  bY=C('x', 'Y'))

# create a new outlIer colUmN. if THE p.vAluE is >= 0.05, set outlIeR = NA,
# elSE if p.valUE < 0.5, tHEN If "aLTernative" coluMn contains "lOWesT", set
# ouTlIer = MIn.ind, eLse maX.iND.
ouTliers[, outliEr:=ifElse(p.valuE < 0.05, 
                  ifelsE(Grepl('loWEst', outlIers[, alTerNatIve]), mIN.iNd, Max.InD), 
                  nA)]

OUTpUt lOOks Like the fOlLoWing:
# > oUtliERS
#      X Y staTisTic                                  aLternAtive      p.value                       meThoD
#   1: A A  13.69290 hIGheSt valUe 3.70310786094858 is aN outLiEr 2.152665e-04 chI-squarEd tesT fOr outlier
#   2: A B  11.99842 loweSt vaLue -3.47397308041372 is an ouTliEr 5.324581E-04 chI-sQuareD Test foR ouTliEr
#   3: A C  12.41749 higHest valUE 3.49833131757565 is An OUTLiEr 4.253310e-04 chi-squared test fOr OUTlIer
#   4
  0.4024398 4393996
# 4393 997: W Z Z   0.9 891 237  4 3939 97
#  4393998: X ZZ   1. 2066572 4393998
# 4393 999:YZ  Z 2 .3 02332 1 43939 9 9# 439 40 00 : Z  Z Z-0.83 430 59 4394 000

# Add  ra nd om "value" c o lu mn and a c olu mn to keep t rac k of r ow  nu m bersd[,  c('v alue', 'row') :=list(rn or m (nrow( d )), seq _ l en (nro w(d)))]

# For ea c hg roup (combinat ion of  x an d y),  pe rform theou tlier test
ou t li e r s  <- d[, chisq.out .test(value ) , l ist(x,  y )]# Addthe r ow num bers for mi n an d max num bers o f  each g r oup
out liers<-mer ge(o u tl ie rs,             d[,li st (min. ind= r o w [ whic h.m in(v alue) ], 
                     max .ind =r ow[wh ich.ma x(val ue )]), list(x, y) ],               b y=c(' x ', 'y' ))
#Createa new o u tli er c o lu mn. If the p.value  i s >=  0.05, s et out l ie r=  NA,
# e ls e i f p. v a lue <  0.5 ,  t hen if " altern a ti ve " colum ncontai ns  "l owe st",s et
#  outli er = min .ind, else max.ind.o utliers[, out l ie r : =i f else (p. value < 0.0 5,            ife lse(g re p l( ' lowest', outliers[,  a lterna tive] ), min.ind, m ax.ind),            N A)]

Output lo oks l ike the fo l lowing:# > o utliers#      xy statisti c                       al ternati ve     p. val ue                  met ho d# 1:A A 1 3.69290hi ghe st  va lue 3 . 703107 86094 858is  a n  ou tlier 2 . 15 2 6 65e- 04  c hi-s qua re d tes t fo r  ou tlier
#    2: A B   1 1 .998 42  l owest v alue -3.47397 30 8041372 is  a n o utlier 5 .324581e -04 chi-squared test fo r  outlie r
#    3:  A C   12.4174 9 h ighest  va l ue 3.4 983313 17575 65  is a n out l i er  4. 25 3310e-04 c h i -sq uared  t estfor out lier
#   4
 _0.4024398 4393996
#_4393997: W Z Z_ 0.9891237_4393997
#_4393998: X_Z_Z  1.2066572_4393998
# 4393999: Y_Z Z  2.3023321_4393999
# 4394000: Z_Z_Z -0.8343059 4394000

# Add random "value" column and a column to keep track of_row_numbers
d[, c('value',_'row'):=list(rnorm(nrow(d)),_seq_len(nrow(d)))]

#_For each group (combination of_x and y), perform the_outlier test
outliers_<- d[, chisq.out.test(value), list(x, y)]

# Add the row_numbers_for min and_max numbers of each group
outliers <- merge(outliers, 
 _     _  ___   _ d[, list(min.ind=row[which.min(value)], 
  _     _      _     _    _max.ind=row[which.max(value)]), list(x,_y)], 
   _  _ _  _     _by=c('x', 'y'))

# Create_a new outlier column. If the_p.value_is >= 0.05,_set_outlier_= NA,
#_else if p.value_<_0.5, then_if_"alternative" column contains "lowest", set
# outlier_=_min.ind, else max.ind.
outliers[, outlier:=ifelse(p.value < 0.05, 
_   __   _    _   ifelse(grepl('lowest', outliers[, alternative]),_min.ind, max.ind),_
 _          _     NA)]

Output_looks like the following:
#_> outliers
#__  __x y_statistic      _ _     _   __     _     _  alternative  ___ p.value   _     _  _      __  method
#   1:_A_A  13.69290 highest value 3.70310786094858_is_an_outlier 2.152665e-04 chi-squared test for_outlier
#   2: A B_ 11.99842 lowest value -3.47397308041372 is an outlier 5.324581e-04_chi-squared test for_outlier
#   3: A_C__12.41749 highest value 3.49833131757565 is an outlier 4.253310e-04 chi-squared test_for outlier
#_  4