I typically keep a battery until it becomes a problem, and by problem, I mean the first time it fails to start the vehicle or the cranking speed is noticeably slower and the battery is over three years old. If less than four years old, I look for an assignable cause, such as a light left on or a bad connection. If I find one, the battery gets one more chance, then its gone.
There is a lot of variation in the lifespan of a battery. I bought a new riding mower in 97, replaced the battery in 99 and 01 and then in, get this, last month. AutoZone verified the date of manufacture as 8/01. In all my riding mowers, two years was about the norm, always used AutoZone batteries for them.
Our 97 Honda has has two Walmart batteries and is currently on a Kirkland (Costco) battery, the battery choice was made on where the battery went dead, twice at Walmart and once at Costco.