I have the following data table:
dt.data <- structure(list(delivMonth = c("2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-04",
"2024-04", "2024-04", "2024-04", "2024-04", "2024-04", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-05", "2024-05", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-05", "2024-05", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-05", "2024-05", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-05", "2024-05", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-05", "2024-05", "2024-05",
"2024-05", "2024-05", "2024-05", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-06", "2024-06", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-06", "2024-06", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-06", "2024-06", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-06", "2024-06", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-06", "2024-06", "2024-06", "2024-06", "2024-06",
"2024-06", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-07", "2024-07", "2024-07", "2024-07",
"2024-07", "2024-07", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-08", "2024-08", "2024-08",
"2024-08", "2024-08", "2024-08", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-09", "2024-09",
"2024-09", "2024-09", "2024-09", "2024-09", "2024-10", "2024-10",
"2024-10", "2024-10", "2024-10", "2024-10", "2024-10", "2024-10",
"2024-10", "2024-10", "2024-10", "2024-10", "2024-10", "2024-10",
"2024-10", "2024-10", "2024-10", "2024-10", "2024-10", "2024-10",
"2024-10", "2024-10", "2024-10", "2024-10", "2024-10", "2024-10",
"2024-10", "2024-10", "2024-10", "2024-10", "2024-10", "2024-10",
"2024-11", "2024-11", "2024-11", "2024-11", "2024-11", "2024-11",
"2024-11", "2024-11", "2024-11", "2024-11", "2024-11", "2024-11",
"2024-11", "2024-11", "2024-11", "2024-11", "2024-11", "2024-11",
"2024-11", "2024-11", "2024-11", "2024-11", "2024-11", "2024-11",
"2024-11", "2024-11", "2024-11", "2024-11", "2024-11", "2024-11",
"2024-11", "2024-11", "2024-12", "2024-12", "2024-12", "2024-12",
"2024-12", "2024-12", "2024-12", "2024-12", "2024-12", "2024-12",
"2024-12", "2024-12", "2024-12", "2024-12", "2024-12", "2024-12",
"2024-12", "2024-12", "2024-12"), quantity = c(-3600, 1440, 0,
-34560, 5760, 0, 7200, 3600, 720, 993.6, 1800, 734.4, 720, -13680,
18252, -842.4, 2880, -3600, -2160, 3600, -3600, 43272, 0, 3600,
-1420.56, 20534.4, 835.2, 345.6, 2160, -7200, -14400, 5040, 720,
-10800, 360, 3600, 1980, 720, -3720, 1488, 0, -35712, 5952, 0,
-7440, 744, 1026.72, 1860, 758.88, 744, -4464, 18860.4, -870.48,
2976, -2232, 3720, -3720, 33554.4, 0, -1467.91, 15266.88, 863.04,
357.12, 2232, -7440, -3720, 5208, 744, 372, 3720, 2046, 744,
-3600, 1440, 0, -34560, 5760, 0, -7200, 720, 993.6, 1800, 734.4,
720, -720, 18252, -842.4, 2880, -2160, 3600, -3600, 32472, 0,
-1420.56, 11174.4, 835.2, 345.6, 2160, -7200, -3600, 5040, 720,
360, 3600, 1980, 720, -3720, 1488, -3720, -35712, 5952, 0, -3720,
3720, 744, 1026.72, 1860, 758.88, 744, -744, 18860.4, -870.48,
2976, 0, -2232, 3720, -3720, 32810.4, 0, -1467.91, 11546.88,
863.04, 357.12, -1488, -7440, -7440, 5208, 744, 372, 3720, 3720,
2046, 744, -3720, 1488, -3720, -35712, 5952, 0, -3720, 3720,
744, 1026.72, 1860, 758.88, 744, -744, 18860.4, -870.48, 2976,
0, -2232, 3720, -3720, 32810.4, 0, -1467.91, 11546.88, 863.04,
357.12, -1488, -7440, -7440, 5208, 744, 372, 3720, 3720, 2046,
744, -3600, 1440, -3600, -34560, 5760, 0, -3600, 3600, 720, 993.6,
1800, 734.4, 720, -4320, 18252, -842.4, 2880, 0, -2160, 3600,
-3600, 31752, 0, -1420.56, 14774.4, 835.2, 345.6, -1440, -7200,
-7200, 5040, 720, 360, 3600, 3600, 1980, 720, 35015, 1490, 0,
21605, 5960, 0, 4470, 1028.1, 1862.5, 759.9, 745, -2980, 18885.75,
-871.65, 2980, 3725, -3725, 32854.5, 0, -1469.89, 12307.4, 864.2,
357.6, 12665, -7450, -3725, 5215, 745, 372.5, 3725, 2048.75,
745, 33840, 1440, 0, 20880, 5760, 0, 4320, 993.6, 1800, 734.4,
720, -7200, 18252, -842.4, 2880, 3600, -3600, 31752, 0, -1420.56,
11894.4, 835.2, 345.6, 12240, -7200, -3600, 5040, 720, 360, 3600,
1980, 720, 34968, 1488, 0, 21576, 5952, 0, 4464, 1026.72, 1860,
758.88, 744, -22320, 18860.4, -870.48, 2976, 3720, -3720, 32810.4,
0), counterparty = c("Axpo (CH)", "Axpo (CH)", "Axpo (CH)",
"CEZ (CZ)", "CEZ (CZ)", "CEZ (CZ)", "DXT Commodities (CH)", "DXT Commodities (CH)",
"EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)", "EnBW (DE)",
"Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)", "Engie (FR)",
"Gunvor (CH)", "Gunvor (CH)", "HSE (SI)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)",
"RWE (DE)", "RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)",
"SEFE (GB)", "SEFE (GB)", "Shell (GB)", "Uniper (DE)", "Uniper (DE)",
"WINGAS (DE)", "WINGAS (DE)", "Axpo (CH)", "Axpo (CH)", "Axpo (CH)",
"CEZ (CZ)", "CEZ (CZ)", "CEZ (CZ)", "DXT Commodities (CH)", "EDF Trading (GB)",
"EDF Trading (GB)", "EDF Trading (GB)", "EnBW (DE)", "Energie AG (AT)",
"Energie Klagenfurt (AT)", "Engie (FR)", "Engie (FR)", "Gunvor (CH)",
"HSE (SI)", "Mercuria (CH)", "Mercuria (CH)", "OMV Gas M&T (AT)",
"OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)", "RWE (DE)", "RWE (DE)",
"RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)", "SEFE (GB)",
"Uniper (DE)", "Uniper (DE)", "WINGAS (DE)", "WINGAS (DE)", "Axpo (CH)",
"Axpo (CH)", "Axpo (CH)", "CEZ (CZ)", "CEZ (CZ)", "CEZ (CZ)",
"DXT Commodities (CH)", "EDF Trading (GB)", "EDF Trading (GB)",
"EDF Trading (GB)", "EnBW (DE)", "Energie AG (AT)", "Energie Klagenfurt (AT)",
"Engie (FR)", "Engie (FR)", "Gunvor (CH)", "HSE (SI)", "Mercuria (CH)",
"Mercuria (CH)", "OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)",
"RWE (DE)", "RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)",
"SEFE (GB)", "SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "WINGAS (DE)",
"WINGAS (DE)", "Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)",
"CEZ (CZ)", "CEZ (CZ)", "DXT Commodities (CH)", "DXT Commodities (CH)",
"EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)", "EnBW (DE)",
"Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)", "Engie (FR)",
"Gunvor (CH)", "Gunvor (CH)", "HSE (SI)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)",
"RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)",
"SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "Vitol (CH)", "WINGAS (DE)",
"WINGAS (DE)", "Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)",
"CEZ (CZ)", "CEZ (CZ)", "DXT Commodities (CH)", "DXT Commodities (CH)",
"EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)", "EnBW (DE)",
"Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)", "Engie (FR)",
"Gunvor (CH)", "Gunvor (CH)", "HSE (SI)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)",
"RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)",
"SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "Vitol (CH)", "WINGAS (DE)",
"WINGAS (DE)", "Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)",
"CEZ (CZ)", "CEZ (CZ)", "DXT Commodities (CH)", "DXT Commodities (CH)",
"EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)", "EnBW (DE)",
"Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)", "Engie (FR)",
"Gunvor (CH)", "Gunvor (CH)", "HSE (SI)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)",
"RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)",
"SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "Vitol (CH)", "WINGAS (DE)",
"WINGAS (DE)", "Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)",
"CEZ (CZ)", "CEZ (CZ)", "EDF Trading (GB)", "EDF Trading (GB)",
"EDF Trading (GB)", "EnBW (DE)", "Energie AG (AT)", "Energie Klagenfurt (AT)",
"Engie (FR)", "Engie (FR)", "Gunvor (CH)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)",
"RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)",
"SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "WINGAS (DE)", "WINGAS (DE)",
"Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)", "CEZ (CZ)",
"CEZ (CZ)", "EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)",
"EnBW (DE)", "Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)",
"Engie (FR)", "Gunvor (CH)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)", "RAG (AT)", "RWE (DE)",
"RWE (DE)", "RWE (DE)", "RWE (GB)", "RWE (GB)", "RWE (GB)", "SEFE (GB)",
"SEFE (GB)", "Uniper (DE)", "Uniper (DE)", "WINGAS (DE)", "WINGAS (DE)",
"Axpo (CH)", "Axpo (CH)", "Axpo (CH)", "CEZ (CZ)", "CEZ (CZ)",
"CEZ (CZ)", "EDF Trading (GB)", "EDF Trading (GB)", "EDF Trading (GB)",
"EnBW (DE)", "Energie AG (AT)", "Energie Klagenfurt (AT)", "Engie (FR)",
"Engie (FR)", "Gunvor (CH)", "Mercuria (CH)", "Mercuria (CH)",
"OMV Gas M&T (AT)", "OMV Gas M&T (AT)"), marketArea = c("CEGH",
"THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "TTF", "CEGH", "THE",
"TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "TTF", "CEGH",
"CEGH", "TTF", "CEGH", "THE", "TTF", "CEGH", "CEGH", "THE", "TTF",
"CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "THE", "TTF", "CEGH",
"TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "CEGH",
"THE", "TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "CEGH",
"CEGH", "TTF", "CEGH", "THE", "CEGH", "CEGH", "THE", "TTF", "CEGH",
"THE", "TTF", "CEGH", "THE", "THE", "TTF", "CEGH", "TTF", "CEGH",
"THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "CEGH", "THE", "TTF",
"TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "CEGH", "CEGH",
"TTF", "CEGH", "THE", "CEGH", "CEGH", "THE", "TTF", "CEGH", "THE",
"TTF", "CEGH", "THE", "THE", "TTF", "CEGH", "TTF", "CEGH", "THE",
"TTF", "CEGH", "THE", "TTF", "CEGH", "TTF", "CEGH", "THE", "TTF",
"TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "TTF", "CEGH", "CEGH",
"TTF", "CEGH", "THE", "CEGH", "CEGH", "THE", "TTF", "CEGH", "THE",
"TTF", "CEGH", "THE", "THE", "TTF", "TTF", "CEGH", "TTF", "CEGH",
"THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "TTF", "CEGH", "THE",
"TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "TTF", "CEGH",
"CEGH", "TTF", "CEGH", "THE", "CEGH", "CEGH", "THE", "TTF", "CEGH",
"THE", "TTF", "CEGH", "THE", "THE", "TTF", "TTF", "CEGH", "TTF",
"CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "TTF", "CEGH",
"THE", "TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "TTF",
"CEGH", "CEGH", "TTF", "CEGH", "THE", "CEGH", "CEGH", "THE",
"TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "THE", "TTF", "TTF",
"CEGH", "TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "CEGH",
"THE", "TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE", "CEGH",
"TTF", "CEGH", "THE", "CEGH", "CEGH", "THE", "TTF", "CEGH", "THE",
"TTF", "CEGH", "THE", "THE", "TTF", "CEGH", "TTF", "CEGH", "THE",
"TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "TTF", "CEGH",
"CEGH", "CEGH", "THE", "THE", "CEGH", "TTF", "CEGH", "THE", "CEGH",
"CEGH", "THE", "TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "THE",
"TTF", "CEGH", "TTF", "CEGH", "THE", "TTF", "CEGH", "THE", "TTF",
"CEGH", "THE", "TTF", "TTF", "CEGH", "CEGH", "CEGH", "THE", "THE",
"CEGH", "TTF", "CEGH", "THE")), row.names = c(NA, -300L), class = c("data.table",
"data.frame"))
I have calculated the total sum of quantity with sum(dt.data$quantity, na.rm = TRUE).
Now I want to create a new table dt.percentage that lists the percentage share/amount of the total quantity for each counterparty. The sum across the new table should add up to 100%, representing the total quantity.
The new table should now only consist of the columns counterparty and percentage, which shows a percentage value for each counterparty with respect to the 100%.
How could this work in R? Is there a base R-function that works here?