title: Count frequency of elements into an array in Lua
body: <p>I have a table in Lua:</p>
  
  <pre>
  p = {'sachin', 'sachin', 'dravid', 'Dhoni', 'yuvraj', 'kohli'}
  </pre>
  
  <p>I want to count frequency of each name in table .    </p>
  
  <pre>
  test1 = {sachin=2, dravid=1, Dhoni=1, yuvraj=1, kohli=1}
  </pre>
  
  <p>I tried this program with lot of for loops .Please see my code</p>
  
  <pre>
  > function exec(ele,p)
  count = 0
  for k,v in pairs(p) do
  if ele == p[k] then
  count = count +1 
  end
  end
  return count
  end
  
  
  > new_table = {}
  > for k,v in pairs(p) do
  new_table[v] = exec(v,p)
  end
  > 
  > for k,v in pairs(new_table) do
  print(k,v)
  end
  dhone   1
  yuvraj  1
  kohli   1
  sachin  2
  dravid  1
  
  </pre>
  
  <p>I want to do this more efficient way. How can I achieve this?</p>