Infants as young as nine months show signs of preferring individuals that are kind to people similar to them and horrible to those who are not.
Researchers from the University of British Columbia found that babies tend to gravitate towards people in the same way as adults to - preferring people who like the same foods, clothes and toys as they do.
However, this is the first study to show that infants condone antisocial behaviour when it is directed at individuals dissimilar to themselves.
Kiley Hamlin and Karen Wynn studied nine and 14-month-old babies by getting them to choose which food they preferred - crackers or green beans.
The babies then watched a puppet show where one puppet preferred crackers and another liked beans.
After both puppets and babies had decided which food they preferred, the infants watched another show, where the puppet dropped its ball and wanted it back.
A separate character always returned the ball while another always refused to give it back.
Infants were then given the chance of picking between the helper and the harmer (the one that did not give the ball back).
The researchers found that babies preferred the character that harmed the puppet which opted for the food they did not like.
Babies preferred the helper when they identified with the puppet by sharing the same food preference.
Hamlin said: "Like adults, infants incorporate information about not only what people do (e.g., acting nicely or meanly) but also whom they do it to (e.g., a person who is liked or disliked) when they make social evaluations."
In a second experiment, a neutral character was introduced. The researchers found that when the puppet was dissimilar, 14-month-old babies like the harmer best, and the neutral character over the helper.
As well as suggesting that infants form negative feelings towards those who help individuals different to themselves, the study also has implications for the mechanisms that underline our interactions with people who are similar and dissimilar.
"The fact that infants show these social biases before they can even speak suggests that the biases aren't solely the result of experiencing a divided social world, but are based in part on basic aspects of human social evaluation," Hamlin said.
She said the infants could be experiencing a form of schadenfreude - where they derive pleasure from the misfortune of others.
"Or perhaps they recognise the alliances that are implied by social interactions, identifying an 'enemy of their enemy' as their friend," Hamlin added.