You didn't mention what the code number was so that makes it very difficult to offer any help.
However assuming that the O2 sensor is working and doing its job a weak mixture to me means the engine is running lean and the problem is some where else.
Subaru manuals are very helpful at tracing down problems when a trouble code is present. Again I don't know the year and model of the engine so offering any help is useless. Sorry
Also there are tests for the sensors to see if they are functioning properly so your not wasting your money an replacing good parts
Here are somethings that cause rough idling, all of these have tests to see if they are good or not in the subaru fsm
2. Rough idling
1) Idle air control solenoid valve
2) Mass air flow sensor
3) Intake manifold pressure sensor
4) Intake air temperature sensor
5) Engine coolant temperature sensor (*2)
6) Ignition parts (*1)
7) Air intake system (*5)
8) Fuel injection parts (*4)
9) Throttle position sensor
10) Crankshaft position sensor (*3)
11) Camshaft position sensor (*3)
12) Oxygen sensor
13) Fuel pump and fuel pump relay
*1: Check ignition coil & ignitor assembly and spark plug.
*2: Indicate the symptom occurring only in cold temperatures.
*3: Ensure the secure installation.
*4: Check fuel injector, fuel pressure regulator and fuel filter.
*5: Inspect air leak in air intake system.
*6: Adjust accelerator cable.
B: GENERAL DIAGNOSTICS