Yep, that was really stupid of you. You may not be able to stop thinking about this subordinate, but you can certainly stop behaving inappropriately. Quit texting her and flirting with her and having lunch with her. Keep your fingers crossed she moves on to a new job or a new department soon, consider seeking a change in your location or department, and, in the mean time, apologize to this subordinate. Explain to her that you were way out of line, that you are deeply sorry for any discomfort you may have caused her, that you regret ever putting your job, her job, or your marriage at risk, and that you hope she’ll accept your apology and you can both move on.
I’d also recommend you start communicating with your wife about your feelings inside your marriage that may have triggered this behavior. Are you feeling under-appreciated? Overwhelmed? Bored? Are your needs not being met? If you and your wife can’t figure out and address these issues between you on your own, you should look into marriage counseling. Consider this transgression at work a wake-up call to start paying attention to your personal life and fixing what’s broken before it’s beyond repair.
If you have a relationship/dating question I can help answer, you can send me your letters at firstname.lastname@example.org.