It is not possible to completely not be affected by other people's behavior. Human beings are social creatures and we are constantly interacting with others. Our interactions with others shape our thoughts, emotions, and behaviors. Even when we try to avoid interacting with others, the actions and words of others can still have an impact on us.
One of the reasons why we are affected by other people's behavior is because we are wired to respond to social cues. Our brains have evolved to recognize and respond to the emotions and actions of others. This is because in our ancestral past, it was important to be able to read and respond to the emotions of others in order to survive in a group. For example, if someone in the group appeared to be angry, it would be important for the rest of the group to be aware of this and respond accordingly.