Among any primitive people the care of one’s livestock is, next to oneself, the most important duty.
Such people therefore become very familiar with the ways of their livestock and, naturally, compare the actions of their fellowmen with the actions and habits of dumb creatures. So it was among the Romans, and so did they pass down to us words with meanings for which we must search among farm animals in explanation.
The Latin word for herd, whether sheep, goats, or cattle, was grex (the root of which is greg-).
Hence, when a band of men joined together into a military company, the people saw that this band, when grouped together, looked like a herd of sheep; so they called the military company grex also. The way the men flocked together, they said, was gregarius, the way of a herd.
This has become gregarious in English, and we still use it to describe a person who is not happy unless with a number of other persons.
The same root has given us the verb aggregate (from Latin aggrego, to add to a herd), which means to collect into a total; and the verb congregate (from Latin congrego, to assemble into a flock or herd), which we use to mean to assemble into a body; and the verb segregate (from Latin segrego, to set apart from the flock or herd), which has come to us with little change in meaning.
From the same root we have also the word egregious. The Latin word, egregius, with the literal meaning, “surpassing the rest of the flock,” was always used in a favorable sense.
This was also the sense in which it was first employed in English, but it then became ironical and is now usually employed in a bad sense; an egregious blunder is one that tops all other blunders.