Perhaps I'm misunderstanding you because your explanation doesn't align with the sample expected output that you've shared.
Each item in Product2 has the same value in Export2 so using the latter to find top_n doesn't make sense. On the other hand, you could find top_n by the Export variable like so:
library(dplyr, warn.conflicts = FALSE)
#> Warning: package 'dplyr' was built under R version 3.6.3
kazex4 <- structure(list(YEAR = c(2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L), Product = c("Petroleum oils, oils from bitumin. materials, crude",
"Copper", "Pig iron & spiegeleisen, sponge iron, powder & granu",
"Petroleum oils or bituminous minerals > 70 % oil", "Wheat (including spelt) and meslin, unmilled",
"Flat-rolled prod., iron, non-alloy steel, not coated", "Zinc",
"Radio-actives and associated materials", "Iron ore and concentrates",
"Natural gas, whether or not liquefied", "Flat-rolled prod., iron, non-alloy steel, coated, clad",
"Ores and concentrates of base metals, n.e.s.", "Aluminium ores and concentrates (incl. alumina)",
"Coal, whether or not pulverized, not agglomerated", "Liquefied propane and butane",
"Aircraft & associated equipment; spacecraft, etc.", "Gold, non-monetary (excluding gold ores and concentrates)",
"Leather", "Meal and flour of wheat and flour of meslin", "Ferrous waste, scrape; remelting ingots, iron, steel",
"Ingots, primary forms, of iron or steel; semi-finis.", "Silver, platinum, other metals of the platinum group",
"Residual petroleum products, n.e.s., related mater.", "Copper ores and concentrates; copper mattes, cemen",
"Lead", "Cotton", "Inorganic chemical elements, oxides & halogen salts",
"Miscellaneous no-ferrous base metals for metallur.", "Barley, unmilled",
"Ball or roller bearings", "Tubes, pipes & hollow profiles, fittings, iron, steel",
"Wool and other animal hair (incl. wool tops)", "Other crude minerals",
"Fish, fresh (live or dead), chilled or frozen", "Sulphur and unroasted iron pyrites",
"Ships, boats & floating structures", "Vegetables", "Manufactures of base metal, n.e.s.",
"Pigments, paints, varnishes and related materials", "Fruits and nuts (excluding oil nuts), fresh or dried",
"Electrical machinery & apparatus, n.e.s.", "Electric current",
"Metallic salts & peroxysalts, of inorganic acids", "Fertilizers (other than those of group 272)",
"Other inorganic chemicals", "Flat-rolled products of alloy steel",
"Tobacco, manufactured", "Petroleum gases, other gaseous hydrocarbons, n.e.s.",
"Civil engineering & contractors' plant & equipment", "Feeding stuff for animals (no unmilled cereals)"
), Export = c(28125875.547, 2774753.829, 1420761.85, 1372686.455,
1170506.955, 1030047.529, 1009023.697, 861280.967, 795650.888,
654776.104, 577914.585, 531876.982, 522493.466, 521783.504, 460815.451,
457163.028, 398898.941, 345676.251, 339222.406, 338749.019, 327587.704,
323202.372, 279972.276, 260366.854, 244857.889, 183686.003, 183079.171,
156656.264, 111366.105, 96351.945, 87312.682, 84810.818, 81225.326,
75315.252, 69763.087, 68704.15, 60793.747, 56920.456, 54593.508,
53949.055, 52598.13, 50108.263, 45667.071, 40731.426, 39928.831,
39790.575, 35430.679, 33444.216, 32675.558, 32171.988), Product2 = c("Petroleum",
"Copper", "Iron_Steel", "Petroleum", "Wheat_Flour", "Iron_Steel",
"Zinc", "Radioactives", "Iron_Steel", "Natural_Gas", "Iron_Steel",
"Ores_metals", "Ores_metals", "Coal", "LPG", "Machinery", "Ores_metals",
"Leather", "Wheat_Flour", "Iron_Steel", "Iron_Steel", "Jewellery_Bullion",
"Petroleum", "Ores_metals", "Lead", "Cotton", "Chemicals", "Miscellaneous",
"Barley", "Iron_Steel", "Machinery", "Meat_Animals", "Petroleum",
"Fish", "Iron_Steel", "Vehicles", "Vegetables", "Ores_metals",
"Chemicals", "Fruits", "Machinery", "Electric current", "Chemicals",
"Chemicals", "Chemicals", "Iron_Steel", "Tobacco", "Petroleum",
"Vehicles", "Meat_Animals"), Export2 = c(130828, 24150, 205281,
130828, 88585, 205281, 24150, 24150, 205281, 24150, 205281, 136835,
136835, 36220, 24150, 90553, 136835, 8034, 88585, 205281, 205281,
30199, 130828, 136835, 24150, 24150, 70402, 24150, 24150, 205281,
90553, 24138, 130828, 24150, 205281, 40248, 12075, 136835, 70402,
10059, 90553, 16105, 70402, 70402, 70402, 205281, 22142, 130828,
40248, 24138)), row.names = c(NA, -50L), class = c("tbl_df",
"tbl", "data.frame"))
kazex4 %>%
group_by(YEAR, Product2) %>%
top_n(3, wt = Export) %>%
arrange(Product2)
#> # A tibble: 38 x 5
#> # Groups: YEAR, Product2 [25]
#> YEAR Product Export Product2 Export2
#> <int> <chr> <dbl> <chr> <dbl>
#> 1 2007 Barley, unmilled 111366. Barley 24150
#> 2 2007 Inorganic chemical elements, oxides & h~ 183079. Chemicals 70402
#> 3 2007 Pigments, paints, varnishes and related~ 54594. Chemicals 70402
#> 4 2007 Metallic salts & peroxysalts, of inorga~ 45667. Chemicals 70402
#> 5 2007 Coal, whether or not pulverized, not ag~ 521784. Coal 36220
#> 6 2007 Copper 2774754. Copper 24150
#> 7 2007 Cotton 183686. Cotton 24150
#> 8 2007 Electric current 50108. Electric cur~ 16105
#> 9 2007 Fish, fresh (live or dead), chilled or ~ 75315. Fish 24150
#> 10 2007 Fruits and nuts (excluding oil nuts), f~ 53949. Fruits 10059
#> # ... with 28 more rows
Created on 2020-04-08 by the reprex package (v0.3.0)
Is this what you are trying to achieve? Let me know if it isn't so that I can help you further.