There are all kinds of reasons why some pigs live longer than others, most of which are unfortunately very much beyond our control.
The fact that you're here, trying to keeping learning about piggies and their needs, surely means that you're a wonderful owner who cares about the welfare of their piggies, trying to give them the best life possible.
I recently had my first piggy die (a couple of months before his 3rd birthday). I was absolutely devastated and asked myself the same question that you're asking now. I wondered what I'd done wrong and couldn't help feeling like I'd failed him as he'd not even reached, what I understand to be, the average life expectancy of a guinea pig.
The truth is, I had cared for this little pig to the best of my ability, based on knowledge and experience I had at that time. Sure, I now know that there were things I could've done differently, but who's to say that the outcome would've been any different if I'd done things differently? You just never know, so it's really not good to think along the lines of "what if...". Some things are just pre-determined and meant to be - we can't always prevent bad things from happening, even with access to the best medical care or all the will in the world. As long as we do our best, whatever that is, then who can argue with that?
Since I lost my beloved piggy, even in a very short space of time I've learned so much and have vowed to keep making changes, as and when I feel improvements can realistically be made, as I gain more experience and learn from everyone here. I want to make sure that I always do my best for my remaining piggy (and any future ones) but I must accept that even then, there are still some things that I can't change, and I just have to deal with those in the best way I can.
Like us humans, even with the very highest standards of care it's still possible for guinea pigs to get sick but as long as we do our best then that's what matters. For caring owners, losing a piggy will never be easy but please try not to be too hard on yourself. Console yourself in the knowledge that you did your best, under whatever circumstances, and that your piggy had the best life possible, for as long or as little time as it was. It's a sad fact that some unfortunate piggies never experience love or security so for your piggies to have found a caring owner such as you, is a special thing.
I really feel for you and hope you can come to terms with things and gain peace of mind, whatever happens x