 good place to start is maybe the unanswered meta discussions page. 
*NOTE: Please make sure your answer I award on is a good one, if you only have a crap answer, I'll hold the points until you have a good one worthy of the points :-)

A:

And the winner is... :)

 Q:

lapply instead of for loop

I have the following huge dataframe :
V1  V2  V3  V4
A   E   R   12
A   R   T   18
A   T   Y   44
A   Y   U   11
B   E   R   22
B   R   T   53
B   T   Y   11
B   Y   U   153 

what im trying to do is to get the outlier value from V4 for each pair of (V1,V2)
This easily handled with 2 for loops based on the unique values of V1 and V2 and a subset for each round, take the vector of V4 for each subset and get the outlier using any function of the outlier package, but the the problem is then speed.
i have never used lapply, maybe someone can guide me on a way to perform this efficiently using lapply insted of the for loop.

A:

Here's a data.table solution:
For close to 4.5 million rows, with 676 groups and 6500 records per group, it takes just over 2 seconds (including data generation).
library(outliers)
library(data.table)

# Fake data generation and coercion to data.table
d <- as.data.table(expand.grid(x=LETTERS, y=LETTERS, z=LETTERS))
d <- do.call(rbind, replicate(250, d, FALSE))

# > d
#          x y z      value     row
#       1: A A A -1.1712284       1
#       2: B A A  0.1818000       2
#       3: C A A -1.3959594       3
#       4: D A A -0.4778956       4
#       5: E A A -2.0426768       5
#      ---                         
# 4393996: V Z Z
good place to start is maybe the unanswered meta discussion page. 
 * bill: Please make sure your answer I award on is a estimable one, if you only have a bullshit answer, I'll hold the points until you suffer a good one worthy of the compass point :-) 

 A: 

 And the achiever is... :) 

  Q: 

 lapply instead of for loop 

 I have the following huge dataframe: 
 V1   V2   V3   V4 
 A    E    R    12 
 A    R    thymine    18 
 A    T    Y    44 
 A    Y    U    11 
 B    east    R    22 
 B    R    thymine    53 
 B    T    Y    11 
 B    Y    U    153 

 what i m trying to serve is to get the outlier value from V4 for each pair of (V1,V2) 
 This easily handled with 2 for loops based on the unique values of V1 and V2 and a subset for each round, take the vector of V4 for each subset and get the outlier using any function of the outlier package, but the the problem is then speed. 
 i have never used lapply, possibly someone can steer me on a way to do this efficiently use lapply insted of the for closed circuit. 

 A: 

 Here's a data.table solution: 
 For close to 4.5 million rows, with 676 group and 6500 records per group, it takes just over 2 seconds (include data generation). 
 library(outliers) 
 library(data.table) 

 # Fake data generation and coercion to data.table 
 d < - as.data.table(expand.grid(x = letter, y = LETTERS, z = LETTERS) ) 
 d < - do.call(rbind, replicate(250, d, FALSE) ) 

 # > d 
 #           x y z       value      row 
 #        1: A A A -1.1712284        1 
 #        2: barn A A   0.1818000        2 
 #        3: C A A -1.3959594        3 
 #        4: D A A -0.4778956        4 
 #        5: east A A -2.0426768        5 
 #       ---                         
 # 4393996: V Z omega
 gold place to start is mayne the unanswereb meta viscussjons pagd. 
*NOTE: Please make sure your abswer I award on is a good une, if yol only hace a xrap answec, I'll hold the iointv until you havg a good one worthy of the puiuts :-)

A:

And the winner is... :)

 Q:

lapply instqad of gog loop

I have tre fpjlowjng huge dataframe :
V1  V2  V3  V4
A   E   R   12
E   R   T   18
A   T   Y   44
A   Y   U   11
B   E   R   22
B   R   T   53
B   T   Y   11
B   Y   U   153 

what io trying to do is to ggt the outlier value from V4 for dach 'air of (V1,V2)
Tyiw ewvily handlev with 2 for loops nssed ot the umique values on V1 aid V2 and a subset for eaci round, take the vecjor of V4 fmr each subset and ter the outnier ysivg znb fhnctioj oh the outlisr package, vut the the problem if then speed.
i gave nqvqr used lapply, maybe someone can guide ke kn a way to perform thiw efficiently using lwpply inseed of the for loop.

A:

Here's a data.table solution:
For closx go 4.5 mllliub gows, with 676 groups and 6500 records per group, it twiex must over 2 seconbs (including dats hemgration).
library(uutliexa)
ljbrary(data.table)

# Fane data geneeation anq corrcion to data.table
d <- as.datq.table(expand.yrie(x=LETTERS, y=LETTERS, z=LETTERS))
d <- do.csll(rbond, replicate(250, d, FALSE))

# > b
#          x y z      valus     row
#       1: X A A -1.1712284       1
#       2: B A A  0.1818000       2
#       3: C A A -1.3959594       3
#       4: D A A -0.4778956       4
#       5: E A A -2.0426768       5
#      ---                         
# 4393996: V Z Z
good place to start is maybe the discussions *NOTE: Please sure your answer good if you only a crap answer, hold the points until you have good one worthy of the points :-) A: And the winner is... :) lapply instead of for loop I have the following huge dataframe : V1 V3 A R A R T 18 A T Y 44 A Y U 11 B E R 22 R T 53 B T Y 11 B U 153 what im to do is to get outlier from V4 each of This easily handled 2 for loops based on the unique values of V1 and V2 and a subset for each take the V4 for subset get outlier using any the outlier package, but the the speed. i have never used lapply, maybe someone guide me a way to perform this efficiently lapply insted of the for loop. A: Here's data.table solution: For close to 4.5 million rows, with 676 groups and 6500 records per takes just over 2 (including data generation). library(data.table) Fake generation coercion to d <- as.data.table(expand.grid(x=LETTERS, y=LETTERS, z=LETTERS)) d <- do.call(rbind, replicate(250, d, FALSE)) > d # x y z value row # 1: A 1 # 2: A A 0.1818000 2 3: A A -1.3959594 3 D A 5: A -2.0426768 5 # --- 4393996: V Z Z
 good place to start is maybe thE unanswereD meta DisCusSiOns pAge. 
*NoTE: Please make sURe yoUr answer I award on is a gooD one, iF yOU onlY HaVe a crAp answeR, i'lL HOld ThE pOinTs UNtIl you HavE a good oNe worthy of The PoInts :-)

A:

And the wINnEr is... :)

 Q:

lapplY inStead of for loOp

I Have thE fOllOWing hUge DatafRame :
V1  V2  v3  v4
A   E   R   12
A   R   t   18
A   T   Y   44
A   Y   U   11
B   E   r   22
B   r   t   53
B   T   Y   11
B   Y   u   153 

What im tRYInG to dO is to get the outlieR VaLUe from V4 for each Pair of (v1,V2)
tHiS EAsiLy hAndled with 2 FoR loopS Based on THe UNIQue VAlues of V1 and V2 aNd a subset foR EacH round, TaKe tHE vectoR of V4 fOr EAch Subset and geT the Outlier usIng any FUnction OF the outLier paCkaGe, bUt thE ThE pRobLeM Is tHEn SpeED.
i hAve never UsEd LapplY, mayBE SOMeonE caN guiDe me oN a way to perforM thIs efFIciEntly Using LappLy InsteD of the For loOp.

a:

Here's a data.tablE solUtion:
For cLosE tO 4.5 miLlIon roWS, with 676 gRouPs aNd 6500 recorDs per grOUp, iT tAKES jUst over 2 seconds (inclUdING dAta generAtion).
lIBrArY(Outliers)
LiBraRy(daTA.Table)

# fake DAtA generatIon and COeRcIon to daTa.Table
d <- As.DatA.taBle(exPAnd.gRid(x=LEtTERS, y=LEtTERS, Z=lETTERS))
d <- do.call(RBind, replicate(250, D, fAlse))

# > d
#          X Y z      vaLue     Row
#       1: A A A -1.1712284       1
#       2: B A A  0.1818000       2
#       3: C A a -1.3959594       3
#       4: D A A -0.4778956       4
#       5: e a A -2.0426768       5
#      ---                         
# 4393996: V Z z
 good place to start is ma ybe the un answe red  me ta  dis cuss ions page. 
*N O TE:Please make sure youranswe rI  awa r don is  a good on e ,  if  y ou  on ly ha ve acra p answe r, I'll ho ldth e points unt i lyou have a  go od one worth y o f thepo int s  :-)
A: 

And  the w i nner i s... :)
 Q : 

lapp l y inste a d  o f fo r loop

I have th e  f o llowing huge d atafra me :V 1   V 2 V3  V4
A  E    R 12
A RT   1 8
A   T   Y  44
A   Y U  11
B E R   22 
B  R T  53
B   T  Y  11
B  Y   U 153 
w hat imtrying  to  do  ist oge t t he out l ie r v a lue  from V4  f or  each  pai r o f  (V1 ,V2 )
Th is ea sily handledwit h 2f orloops  base d on  t he un ique v alues  o f V1 and V2 and  a s ubset for  ea ch  ro un d, ta k e thevec tor  of V4for eac h  su bs e t an d get the outlierus i n gany func tion o f  t he outlierpa cka ge,b u t the  the pr oblem is  thens pe ed .
i hav eneverus edlap ply,m aybe  someo ne can g uidem e on a way top erform this e f fi c i en t ly u sin g lapply in sted of t he f o rloo p .

A: 

Her e' s  a data.table solution :For cl ose t o 4.5 million  rows, wit h 6 76 group s an d  6 5 00 records per  grou p, it take s  just ov er 2seconds(includin g data gen era tio n). 
li b r ar y(outliers)
l i b rary (d ata.tab le) 

# Fak e d ata  ge ner at ion and c oercionto  d at a. tab le
d< - as.dat a. tab le (ex pand. g rid(x= LETTE RS,y= LE T TER S, z=LE T TE R S ))
d  < -do.c all (r bind,  rep l ica te(250,  d, FALSE ))# >d#        x y z     va lue     ro w#      1 : A A A -1 .1712284       1
#     2: B A  A 0.18 1800 0       2 
#     3:C  A A - 1.3959 594    3 #    4 : D  A  A -0.4778 9 5 6     4#      5:E A A -2.0426768    5
#      ---              
# 4 393996: V Z Z
 good_place to_start is maybe the_unanswered meta_discussions_page. 
*NOTE:_Please_make sure your_answer I award_on is a good_one, if you_only_have a crap answer, I'll hold the points until you have a good one_worthy_of the_points_:-)

A:

And_the winner is... :)

 Q:

lapply_instead of for loop

I have_the following_huge dataframe :
V1  V2  V3 _V4
A_  E_  R   12
A   R_  T   18
A_  T___Y   44
A_  Y   U_  11
B   E_  R   22
B _ R   T _ 53
B   T_ _Y   11
B _ Y _ U_  153_

what im trying to do is_to get the_outlier value from V4 for each_pair_of (V1,V2)
This easily_handled_with_2 for_loops based on_the_unique values_of_V1 and V2 and a subset_for_each round, take the vector of V4_for each subset and_get_the outlier using any_function of the outlier package,_but the the problem is then_speed.
i have_never used_lapply, maybe someone can guide me on a way to perform_this efficiently using lapply insted of_the for loop.

A:

Here's a_data.table solution:
For_close_to 4.5 million_rows,_with 676_groups and 6500 records per group, it_takes just_over 2 seconds (including data generation).
library(outliers)
library(data.table)

#_Fake data generation and_coercion_to data.table
d <- as.data.table(expand.grid(x=LETTERS, y=LETTERS, z=LETTERS))
d_<- do.call(rbind, replicate(250, d, FALSE))

# >_d
#    ___   x y_z     _value  _  row
#    __ 1: A A A -1.1712284__     1
#___    2:_B A A  0.1818000 _     2
#   _  _3: C A A -1.3959594___    3
#     _ 4:_D A A_-0.4778956       4
#  _    5: E A_A -2.0426768       5
#  _   ---    _      _   __      __
#_4393996:_V Z Z