Stock indexes ticked lower on Thursday after flipping multiple times between small gains and losses. It is the latest meandering course for a market that has been pushed in many directions the last few weeks.

Food companies struggled after the makers of Spam and Folgers coffee reported weaker-than-expected results, and grocers fell after Amazon said it planned to cut prices for avocados, eggs and other products when it takes control of Whole Foods next week. Retailers were big winners after a wide range of them said they earned larger profits last quarter than Wall Street had forecast.

The Standard & Poor’s 500-stock index fell 5.07 points, or 0.2 percent, to 2,438.97. The Dow Jones industrial average fell 28.69 points, or 0.1 percent, to 21,783.40. The Nasdaq composite fell 7.08 points, or 0.1 percent, to 6,271.33.

The market has drifted up and down since the S.&P. 500 set a record high earlier this month. Helping stocks has been strong growth in profits, and most S.&P. 500 companies have reported higher earnings for the spring quarter than analysts forecast, and also healthier revenue.