Train derailments happen, but are still very rare here, especially considering the millions of passengers every day and the size of the NYC subway system. People who live here rarely consider that it will happen. Derailments do also happen on the commuter lines. (One recently on a MetroNorth line killed four people when the driver nodded off at high speed.) Subway derailments and accidents are usually repaired within a few days, but it can take longer for the commuter lines. Inside the city itself there is usually an alternate route, such as a nearby bus route or another subway line. For commuters it can be more problematic, but they do run shuttle buses along some MetroNorth routes when this happens. And in the New Jersey suburbs, the buses honor train tickets when a commuter line is out of service.
Here's a list of some recent subway accidents incidents.
www.nycsubway.org: Subway FAQ: Accidents