title: Adding prefix to the duplicated row entries in R dataframe
body: <p>I have created the following Dataframe in R studio using the following commands</p>
  
  <pre><code>  Sample_df$First_Val&lt;-NA
   #  WE NOW FILL IN THE VALUES AS NEEDED
    Sample_df$First_Val[c(2,3,5,10,14,19,20,21,25,30)]&lt;-paste0("[LO]_", 
    c(2,3,5,10,14,19,20,21,25,30))
  
    ## WE NOW FILL IN THE INTERIM VALUES HERE
    Sample_df$First_Val[1]&lt;-"A1"
    Sample_df$First_Val[19]&lt;-"A19"
    Sample_df$First_Val[3]&lt;-NA
    Sample_df$First_Val[4]&lt;-c("A4")
  
    Sample_df$First_Val[c(6,7,8,9)]&lt;-c("B", "C", "D", "A2")
  
    Sample_df$First_Val[c(11,12,13)]&lt;-c("P", "Q", "A3")
  
   Sample_df$First_Val[c(15,16,17,18)]&lt;-c("B", "C", "D", "D")
  
   Sample_df$First_Val[c(22,23,24)]&lt;-c("P", "Q", "A_5")
  
   Sample_df$First_Val[c(26,27,28, 29)]&lt;-c("M", "N", "P", "A_6")
   Sample_df$First_Val[is.na(Sample_df$First_Val)]&lt;-c("M", "B", "O", "M", 
  'AQII', "B", "o", "L", 'I', "U", "[LO]")
  </code></pre>
  
  <p>The dataframe looks as follows</p>
  
  <pre><code>     SlN0 First_Val
        1        A1
        2    [LO]_2
        3         M
        4        A4
        5    [LO]_5
        6         B
        7         C
        8         D
        9        A2
       10   [LO]_10
       11         P
       12         Q
       13        A3
       14   [LO]_14
       15         B
       16         C
       17         D
       18         D
       19       A19
       20   [LO]_20
       21   [LO]_21
       22         P
       23         Q
       24       A_5
       25   [LO]_25
       26         M
       27         N
       28         P
       29       A_6
       30   [LO]_30
       31         B
       32         O
       33         M
       34      AQII
       35         B
       36         o
       37         L
       38         I
       39         U
       40      [LO]
       41         M
  </code></pre>
  
  <p>The following is the expected output</p>
  
  <pre><code>     SlN0     First_Val
        1            A1
        2        [LO]_2
        3   A1_[LO]_2_M
        4            A4
        5        [LO]_5
         6   A4_[LO]_5_B
         7   A4_[LO]_5_C
         8   A4_[LO]_5_D
         9            A2
        10       [LO]_10
        11  A2_[LO]_10_P
        12  A2_[LO]_10_Q
        13            A3
        14       [LO]_14
        15  A3_[LO]_14_B
        16  A3_[LO]_14_C
        17  A3_[LO]_14_D
        18  A3_[LO]_14_D
        19           A19
        20       [LO]_20
        21       [LO]_21
        22 A19_[LO]_20_P
        23 A19_[LO]_20_Q
        24           A_5
        25       [LO]_25
        26 A_5_[LO]_25_M
        27 A_5_[LO]_25_N
        28 A_5_[LO]_25_P
        29           A_6
        30       [LO]_30
        31 A_6_[LO]_30_B
        32 A_6_[LO]_30_O
        33 A_6_[LO]_30_M
        34          AQII
        35         AQII_B
        36             o
        37  L
        38  I
        39  U
        40          [LO]
        41          [LO]_M
  </code></pre>
  
  <p>The First_Val column changes as follows. </p>
  
  <p>In case there are duplicated entries in First_Val column between 2 [LO] values , we append(using paste) the 2 immediately preceding values. Thus entry 3 in First_Val column (M) changes to A1_[LO]_2_M. </p>
  
  <p>In case an entry has no duplicate values such as o, L, I etc- these remain unchanged as they are unique values. </p>
  
  <p>In case there are multiple [LO] values before a series of duplicates, then the most recent [LO] value is appended along with the preceding value. Example- rows 22,23. Thus a duplicate entry preceded by one unique value is pasted with that unique value. In case there are 2 unique values before a duplicate value, we paste both value's to the duplicate value. </p>
  
  <p>I request someone to help here. </p>