Click on the city hex where the factory is then click the city name in the upper right side corner while being in railroad mode (F2 I think) and you should get the factory list and arrows that point left and right (like this: << >>). Once you have chosen the number of factories to rail out you right-click on the city you want the factories to rail to.