idle problem

2002 Montero Sport

When in park, my Montero idles smooth but when I put it in gear, it “misses” or idles rough. What can cause this to happen?