title: Merging Duplicate Rows and apply Pivot_wider
body: <p>I have the following dataset format:  </p>
  
  <pre><code>structure(list(ï..Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
  2L), .Label = c("1/1/2019", "1/2/2019"), class = "factor"), ID = structure(c(1L, 
  1L, 1L, 2L, 2L, 2L, 2L), .Label = c("AAA001", "BBB002"), class = "factor"), 
      Gender = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("FEMALE", 
      "MALE"), class = "factor"), Measure = structure(c(1L, 2L, 
      4L, 3L, 3L, 3L, 4L), .Label = c("Mental Status", "Motor Function", 
      "No. 1", "Score"), class = "factor"), Value = structure(c(6L, 
      6L, 5L, 1L, 2L, 3L, 4L), .Label = c("1.", "2/2/2020", "3811: Satisfactory", 
      "4", "7", "Normal"), class = "factor")), class = "data.frame", row.names = c(NA, 
  -7L))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> df
    ï..Date     ID Gender        Measure              Value
  1 1/1/2019 AAA001   MALE  Mental Status             Normal
  2 1/1/2019 AAA001   MALE Motor Function             Normal
  3 1/1/2019 AAA001   MALE          Score                  7
  4 1/1/2019 BBB002 FEMALE          No. 1                 1.
  5 1/1/2019 BBB002 FEMALE          No. 1           2/2/2020
  6 1/1/2019 BBB002 FEMALE          No. 1 3811: Satisfactory
  7 1/2/2019 BBB002 FEMALE          Score                  4
  &gt; 
  </code></pre>
  
  <p>I tried the following but encountered errors, which came out with almost 7000 duplicates, mainly due to the duplicate rows of Measures for the same ID:</p>
  
  <pre><code>df %&gt;%
  +         distinct() %&gt;%
  +         pivot_wider(names_from = 'Measure', values_from = 'Value')
  # A tibble: 3 x 7
    ï..Date  ID     Gender `Mental Status` `Motor Function`       Score     `No. 1`
    &lt;fct&gt;    &lt;fct&gt;  &lt;fct&gt;      &lt;list&lt;fct&gt;&gt;      &lt;list&lt;fct&gt;&gt; &lt;list&lt;fct&gt;&gt; &lt;list&lt;fct&gt;&gt;
  1 1/1/2019 AAA001 MALE               [1]              [1]         [1]         [0]
  2 1/1/2019 BBB002 FEMALE             [0]              [0]         [0]         [3]
  3 1/2/2019 BBB002 FEMALE             [0]              [0]         [1]         [0]
  Warning message:
  Values in `Value` are not uniquely identified; output will contain list-cols.
  * Use `values_fn = list(Value = list)` to suppress this warning.
  * Use `values_fn = list(Value = length)` to identify where the duplicates arise
  * Use `values_fn = list(Value = summary_fun)` to summarise duplicates 
  </code></pre>
  
  <p>The expected output should be like the following:</p>
  
  <pre><code>      Date     ID Gender Mental.Status Motor.Function                            No.1 Score
  1 1/1/2019 AAA001   MALE        Normal         Normal                                     7
  2 1/1/2019 BBB002 FEMALE                              1. 2/2/2020, 3811: Satisfactory     4
  </code></pre>
  
  <p>Appreciate for your help in advance!</p>