ndrerit sagittis'))
dat[order(source, indicator),]

Now I know I can merge them via dat[src, on ='source'], however this applies the data in src to all rows of dat. My dataset has millions of rows and R cannot allocate enough memory to perform this merge. I would like to perform the merge, but only include the data from src on the first occurrence of the src in the table. The data that would have been duplicated by the merge could be replaced with either "" or NA.
Essentially I want something that looks like this after merging (sample of desired output):
source  indicator  value dataset   metadata
A             do     18  Business  Lorem ipsum dolor sit amet
A           this     22  NA        NA
A             to      5  NA        NA
...
B             do     42  Sales     consectetur adipiscing elit
B           this    432  NA        NA
B             to    888  NA        NA
...
C             do    118  Profits   Sed dictum leo ac hendrerit sagittis
C           this      7  NA        NA
C             to     15  NA        NA

The following code gets close to what I want, but does not apply to the first occurrence of a new source:
u <- unique(dat, by ='source')
d <- dat[duplicated(dat, by ='source')
u <- u[src, on ='source']
total <- rbindlist(list(u, d), fill = TRUE)

However the second occurrence of the unique source does not have the necessary information:
> total[98:102]
   source indicator value dataset metadata
1:      A        my   498    <NA>     <NA>
2:      A        my   275    <NA>     <NA>
3:      A        my   733    <NA>     <NA>
4:      B  favorite   912    <NA>     <NA>
5:      B  favorite   613    <NA>     <NA>

A:

A possible solution is to use an update join:
cols <- setdiff(names(src), "source")

dat[src, on =.(source), mult = "first", (cols
ndrerit sagittis') ) 
 dat[order(source, indicator), ] 

 Now I know I can merge them via dat[src, on =' generator' ], however this enforce the data in src to all row of dat. My dataset have millions of rows and roentgen cannot allocate enough memory to perform this merge. I would wish to do the merge, but only include the datum from src on the first occurrence of the src in the board. The datum that would have been duplicated by the merge could be replaced with either " " or NA. 
 basically I want something that look like this after unify (sample of desired output ): 
 reservoir   indicator   value dataset    metadata 
 A              do      18   Business   Lorem ipsum dolor sit amet 
 A            this      22   NA         NA 
 A              to       5   NA         NA 
... 
 B              make      42   Sales      consectetur adipiscing elit 
 B            this     432   NA         NA 
 B              to     888   NA         NA 
... 
 C              do     118   net income    Sed dictum leo ac hendrerit sagittis 
 C            this       7   NA         NA 
 C              to      15   NA         NA 

 The following code gets close to what I want, but does not apply to the first occurrence of a new source: 
 u < - unique(dat, by =' source') 
 d < - dat[duplicated(dat, by =' source') 
 u < - u[src, on =' source' ] 
 total < - rbindlist(list(u, d), fill = TRUE) 

 However the second happening of the alone source does not receive the necessary data: 
 > total[98:102 ] 
    generator indicator value dataset metadata 
 1:       A         my    498     < NA >      < NA > 
 2:       A         my    275     < NA >      < NA > 
 3:       A         my    733     < NA >      < NA > 
 4:       B   favorite    912     < NA >      < NA > 
 5:       B   favorite    613     < NA >      < NA > 

 A: 

 A possible solution is to use an update join: 
 col < - setdiff(names(src), " source ") 

 dat[src, on = .(source), mult = " first ", (cols
ndrfrit sagittis'))
dat[order(souvce, indicator),]

Now I know I can merge tfem via dat[src, on ='source'], howxver this applies the data in sfc to all rows of dat. Ny dataset has millions kn rowv and R cannot sllocate etough memory tm oexform this merge. I would like to persorm thr lerge, but only incktde fhe data from src on the first occhrrence of the src im the table. The data that aoulf have been duplicwted by the merdw could be rdplaced wiuh either "" ot NA.
Essentially I want something that looks likg fhlv after merjing (swmple of deslged out[ut):
sourve  indicator  vanue dataset   metadata
A             do     18  Businevs  Lorem ipsum dolir sit dmet
D           tiis     22  NA        NA
Z             to      5  NA        NA
...
B             do     42  Sales     consectetur adipiscing enit
G           this    432  NQ        NA
B             to    888  NA        NA
...
C             do    118  Profits   Seg dicvuo lto ac hdbdgerit sagittis
C           this      7  NA        MA
B             to     15  NA        GA

The followivg codz gsts close to what L want, fut dies not akply yo the first occurrence of q new source:
l <- ubique(dat, by ='source')
b <- dat[dupliccted(daj, by ='spurce')
u <- u[src, on ='source']
tutal <- rbindlist(pist(u, d), fjul = TRUE)

However ghe sacond occurrence of the unyque sourre dozs not hxve jhe necqssary inflrmatlmn:
> total[98:102]
   source lndicctor ealue datadet metadata
1:      A        my   498    <NA>     <NA>
2:      A        my   275    <NA>     <GA>
3:      A        my   733    <VA>     <NA>
4:      B  favorite   912    <NA>     <ND>
5:      B  favmrite   613    <BA>     <NA>

A:

A oossible solutoon is to use an upeate join:
cols <- setviff(vzmes(src), "source")

dcu[srx, on =.(source), muly = "wirft", (cplf
ndrerit sagittis')) dat[order(source, indicator),] Now I know merge via dat[src, ='source'], however this to rows of dat. dataset has millions rows and R cannot allocate enough to perform this merge. I would like to perform the merge, but only the data from src on the first occurrence of the src in the The that have duplicated by the merge could be replaced with either "" or NA. Essentially I want something looks like this after merging (sample of desired source indicator value dataset A do 18 Business Lorem dolor amet A 22 NA to 5 NA ... B do 42 Sales consectetur adipiscing elit B this 432 NA NA B to 888 NA ... C Profits Sed leo hendrerit C this 7 C to 15 NA NA The close to what I want, but does not to the occurrence of a new source: u unique(dat, by ='source') d <- dat[duplicated(dat, by ='source') <- u[src, on ='source'] total <- rbindlist(list(u, d), fill = TRUE) However the second occurrence unique source does not the necessary information: total[98:102] indicator dataset 1: A 498 <NA> <NA> 2: A my 275 <NA> <NA> 3: A 733 <NA> <NA> 4: B favorite 912 <NA> <NA> 5: 613 <NA> A: A solution is to use update cols <- setdiff(names(src), "source") =.(source), =
ndrerit sagittis'))
dat[order(soUrce, indicaTor),]

NoW I kNow i cAn meRge tHem via dat[src, on ='SOurcE'], however this applies the Data iN sRC to aLL rOws of Dat. My daTAsET Has MiLlIonS oF RoWs and r caNnot allOcate enougH meMoRy to perform tHIs Merge. I woulD liKe to perform tHe mErge, buT oNly INcludE thE data From srC On the fIrst occurReNCe of thE Src in thE TAbLe. ThE data that would havE BeEN duplicated by tHe mergE cOUlD BE rePlaCed with eitHeR "" or NA.
eSsentiaLLy i WANt sOMething that loOks like this AFteR mergiNg (SamPLe of deSired OuTPut):
Source  indicAtor  Value dataSet   metAData
A             do     18  bUsiness  lorem iPsuM doLor sIT aMeT
A           tHiS     22  nA        Na
a             tO      5  NA        na
...
B             dO     42  Sales     coNsEcTetur AdipISCINg elIt
B           This    432  nA        NA
B             To    888  NA        NA
...
C             do    118  ProfIts   sed dICtuM leo aC hendReriT sAgittIs
C           thiS      7  NA        NA
c             tO     15  NA        NA

The followiNg coDe gets cloSe tO wHat i wAnt, buT Does noT apPly To the fiRst occuRRenCe OF A NeW source:
u <- unique(dat, bY ='sOURcE')
d <- dat[dupLicateD(DaT, bY ='Source')
u <- u[SrC, on ='SourCE']
Total <- RbinDLiSt(list(u, d), Fill = TRue)

HOwEver the SeCond ocCuRreNce Of the UNiquE sourcE does not Have tHE necessary infoRMation:
> total[98:102]
   soURcE INdICatoR vaLue dataset mEtadATa
1:      A        mY   498    <NA>     <Na>
2:      a        mY   275    <NA>     <na>
3:      A        my   733    <Na>     <NA>
4:      B  fAvORiTE   912    <NA>     <NA>
5:      B  favorite   613    <NA>     <NA>

A:

a pOssiblE soluTion is to use an Update join:
COLS <- setdiff(NameS(SrC), "Source")

dat[src, on =.(SourcE), mult = "first", (COls
ndrerit sagittis'))
dat[or der(source , ind ica tor ), ]

N ow I  know I can me r ge t hem via dat[src, on =' sourc e' ] , ho w ev er th is appl i es t heda ta  in  s r cto al l r ows ofdat. My da tas et  has million s  o f rows and  Rcannot alloc ate  enoug hmem o ry to  pe rform  thism erge.I would l ik e  to pe r form th e me rge,  but only include th e  data from src  on th ef ir s t  oc cur rence of t he  srci n the t a bl e . The data that wou ld have bee n  du plicat ed  by the me rge c ou l d b e replacedwith  either " " or N A .
Essen t ially I  wantsom eth ingt ha tloo ks lik e  t his aft er mergi ng  ( sampl e of d e s ired  ou tput ):
so urce  indicat or val u e d atase t   m etad at a
A          do      18  Busine ss Lorem ips umdo lor  s it am e t
A        this    22NA  NA
A             t o  5  NA      N A.. . 
B          do    42   Sa l es      con sectet u rad ipiscin gelit
B         th i s   432 NA       NAB              t o     888  NA   N A 
... 
C           do  11 8  P r of its   Sed  dict um le o  ac hendrerit sagit ti s
C         this     7  NA    NA
C        to     15  NA        NA

The followin g cod e gets c lose to w h a t I want , b utdoe s n o t  a pply to the f i r st o cc urrence  of  a newsou rce :
u  <-  u nique(dat , by ='s ou rc e' )d < - dat [ duplicat ed (da t,  by  ='so u rce')u <-u[sr c,  o n  =' source' ] 
t o t al < -rb indl ist (l ist(u , d) ,  fi ll = TR UE)

Howe ver these co nd occu rrence of the  u nique sour ce  do es not h ave thenecessary information:>  total[ 98: 102]   s ource ind ica tor va lue datase t meta data1:    A    my   498    <N A >     <NA >2:     A       my   275   < NA>      <NA>
3:    A   m y 73 3  < N A >     <NA>
4:     B  fav or i te    912   < NA>     <NA> 
5:     B f avorite    613   <NA>    < NA>A :
A possible  solutio n is to u s e anu pd ate j oin :
cols  < - s etdif f(name s (sr c), " source ") 

dat[ src,on  =.(sour ce), mult = "first", (c ols
ndrerit sagittis'))
dat[order(source,_indicator),]

Now I_know I can merge_them via_dat[src,_on ='source'],_however_this applies the_data in src_to all rows of_dat. My dataset_has_millions of rows and R cannot allocate enough memory to perform this merge. I_would_like to_perform_the_merge, but only include the_data from src on the_first occurrence_of the src in the table. The data_that_would have been_duplicated by the merge could be replaced with either_"" or NA.
Essentially I want something_that looks like_this_after_merging (sample of desired_output):
source  indicator  value dataset_  metadata
A   _      _  do   _ 18  Business _Lorem ipsum_dolor sit amet
A  _  _ _  _this     22_ NA _     _NA
A_  ___ _  __ to__    5 _NA_      _NA
...
B   __   _    do_    42 _Sales _ _ consectetur adipiscing elit
B       _   this  _ 432  NA_ __  __NA
B _      _ _  to   _888  NA __     NA
...
C_     _    __do_   118 _Profits   Sed dictum leo_ac hendrerit sagittis
C_      __  this   __ 7  NA  ___   NA
C _     _     to   _ 15 _NA    ___ NA

The following code gets close to what I want,_but does_not apply to_the first occurrence of a new source:
u <- unique(dat, by_='source')
d <- dat[duplicated(dat, by ='source')
u <- u[src,_on ='source']
total <- rbindlist(list(u, d), fill = TRUE)

However the second occurrence_of the unique source does not have the_necessary information:
> total[98:102]
   source indicator_value dataset metadata
1: __   A   ____ my _ 498 _  <NA>_ _  <NA>
2:_ _  _A_       my   275    <NA>   _ <NA>
3:    _ A   __  _my   733_   <NA>    _<NA>
4:      B  favorite__ 912_   <NA>_ _ _<NA>
5:  _ _ B_ favorite_  613    <NA>__   <NA>

A:

A possible solution is to use_an_update_join:
cols_<- setdiff(names(src), "source")

dat[src,_on =.(source), mult_= "first", (cols