On your original Q post, you asked if factories were useless if all the improvement tiles had been used and no starport had been built.
First, you can change/upgrade almost any improvement to another. The exceptions, IIRC, are a few that one cannot demolish. I believe one of those is the Mind Control Center. Thus, if you gained a planet that had, say, 10 tiles and all 10 were factories, you could upgrade (or demolish and build) a factory to a starport.
Second, you could use Focus to turn some of the factory output into Research.
Note that late in some games, especially when using "Fast" or Very Fast" research settings, a player will decide that all the useful techs have been researched. At that point, all Research improvements get "plowed under" or "upgraded" into factories, farms, morale, economic improvements. The most common switch might be turning them into Manufacturing Centers and Stock Exchanges.