Generate table for total number of SV events per sample I have called and annotated structural variants and I have a table by name of samples and structural events like below

Sample  Type
t_005   DEL
t_005   INS
t_005   DEL
t_005   DEL
t_005   DEL
t_005   DEL
t_005   DUP
t_005   DUP
t_005   DEL
t_005   DEL
t_005   DEL
t_005   DEL
t_005   DUP
t_005   BND
t_005   DEL
t_005   DEL
t_005   BND
t_005   DEL
t_005   DEL
t_005   DUP
t_005   DEL
t_005   DEL
t_005   DEL
t_005   DEL


How can I count the number of events to get the below table?

&gt; head(SV_Counts[,1:4])
               t_005      o_005       t_013         o_013
    DEL          27          40          25          30
    DUP          11          10          13          22
    BND          23          20          10          12
    TRA           3           2           4           4
    &gt;


I tried this from google but I failed to adapt my data to that

    &gt; melt(table(a))
   Sample Type value
1   o_036  BND   280
2   o_005  BND     8
3   o_013  BND   160
4   o_021  BND   144
5   o_036  BND     0
6   t_005  BND    15
7   t_013  BND   108
8   o_036  DEL    63
9   o_005  DEL    15
10  o_013  DEL   121
11  o_021  DEL   243
12  o_036  DEL     0
13  t_005  DEL    40
14  t_013  DEL    76
15  o_036  DUP    34
16  o_005  DUP     4
17  o_013  DUP    57
18  o_021  DUP    88
19  o_036  DUP     0
20  t_005  DUP    14
21  t_013  DUP    48
22  o_036  INS    58
23  o_005  INS     0
24  o_013  INS     4
25  o_021  INS    10
26  o_036  INS     1
27  t_005  INS     1
28  t_013  INS     2


But hereafter I don't know what to do
So you have data in "long format" and want to convert it to "wide format". You can use spread() from tidyr for that:

require(tidyr)
# Assuming your input is called `foo`
spread(foo, Sample, value)