I'm sorry for the friends you've lost, but I have to tell you I'm glad you posted because I've asked myself this same question many times: Why did this friend's life end and not mine? Maybe we all ask ourselves these questions, I don't know, but it's a particularly difficult one for me because I have very strong beliefs in the afterlife, which means--I know this sounds weird--I wouldn't mind going there now and I also wouldn't mind staying here. So, it just seems logical to me that my life should be taken rather than somebody else's. I've asked others in my life about this, and recently when I asked one person "why not me instead of my friend?", she immediately said "because God doesn't want you there now, and he doesn't want me either!" She went on to say that the "logic" of God is different from ours, that it's not about what WE want or what WE think. It's about how we can serve and who we can help, and how we can inspire others here on earth. I'm not sure how it happened, but somehow that made me feel better. Hope it helps you as well.
Hugs & prayers,