I wrote a for loop to calculate the totals of one variable ("value") for each category of another ("currency"). In essence, I want to know the total value for each currency in my data set ("q4totalnetassets").
I am able to produce the output that I want, but the output contains an extra component with value 0.000 that shouldn't be in the vector:
Here's my code for the "for loop":
sums = c()
for(i in levels(q4totalnetassets$Currency)){
sums[i] = sum(q4totalnetassets$Value[q4totalnetassets$Currency == i & q4totalnetassets$Country != "TOTAL"])
}
sums
Here's my data:
> q4totalnetassets[, c(1, 8, 9)]
Country Value Currency
216 TOTAL 8199900.6820 EUR
1956 Austria 79205.5520 EUR
3696 Belgium 76531.2991 EUR
5436 Bulgaria 795.5987 BGN
7176 Croatia 13857.6950 HRK
8916 Czech Republic 202580.4473 CZK
10656 Denmark 804999.1900 DKK
12396 France 762929.0000 EUR
14136 Germany 309851.7970 EUR
15876 Greece 4422.0000 EUR
17616 Hungary 148981.6908 HUF
19356 Ireland 1446873.0000 EUR
21096 Italy 226043.3900 EUR
22836 Liechtenstein 27902.8000 CHF
24576 Luxembourg 2946860.0000 EUR
26316 Malta 2737.3674 EUR
28056 Netherlands 34186.0000 EUR
29796 Poland 92855.8900 PLN
31536 Portugal 7577.3618 EUR
33276 Romania 20974.2320 RON
35016 Slovakia 3973.8010 EUR
36756 Slovenia 2308.6453 EUR
38496 Spain 185420.0000 EUR
40236 Switzerland 444451.1453 CHF
41976 Turkey 37598.8612 TRY
43716 United Kingdom 795221.1740 GBP
45456 Finland 78619.0081 EUR
47196 Sweden 2411741.0000 SEK
48936 Norway 904348.0000 NOK
Any ideas on why the extra category is appearing?