Lewis Hamilton has taken the lead in the Formula One drivers' championship by winning the Singapore Grand Prix, leapfrogging teammate Nico Rosberg who had to retire early with a gear-selection failure.