I have an Excel sheet containing employment numbers of each industry of each county in the US.

It looks like this:

```
County   Industry  Employees
a        1         49
a        2         1
b        1         4
b        2         19
...

```

I want to calculate the [Herfindahl-Hirschman index](http://www.investopedia.com/terms/h/hhi.asp) (HHI) of employment in each county. I'm using R.
Given some numbers, calculating the HHI is easy:

```
hhi <- function(x) {
  # calculate sum
  total <- sum(x)

  # calculate share
  share <- x*100/total

  # add
  return(sum(share^2))

}

```

So, for example, county 1 has a HHI of 9608 (= 98^2 + 2^2) and county 2 has a HHI of 7127.

But how can I create a new column with the HHI of that county?