Stocks ended higher on Friday and the S&P 500 posted its best week in nine as the market defied calls for a pullback.

Investors rotated into defensive and lagging sectors in a move that could intensify in coming weeks.

Based on the latest available data, the Dow Jones industrial average <.DJI> was up 29.44 points, or 0.24 percent, at 12,091.70. The Standard & Poor's 500 Index <.SPX> was up 3.73 points, or 0.29 percent, at 1,310.83. The Nasdaq Composite Index <.IXIC> was up 15.42 points, or 0.56 percent, at 2,769.30.

For the week, the Dow was up 2.3 percent, the S&P 500 was up 2.7 percent and the Nasdaq was up 3 percent.

(Reporting by Caroline Valetkevitch; Editing by Kenneth Barry)