We study the interplay of 3d and 4f electrons in the iron pnictides CeFe1−xCoxAsO and GdFe1−yCoyAsO, which correspond to two very different cases of 4f -magnetic moment. Both CeFeAsO and GdFeAsO undergo a spin-density-wave (SDW) transition associated with Fe 3d electrons at high temperatures, which is rapidly suppressed by Fe/Co substitution. Superconductivity appears in a narrow doping range: 0.05 < x < 0.2 for CeFe1−xCoxAsO and 0.05 < y < 0.25 for GdFe1−yCoyAsO, showing a maximum transition temperature Tsc of about 13.5 K for Ce and 19 K for Gd. In both compounds, the 4f -electrons form an antiferromagnetic (AFM) order at low temperatures over the entire doping range and Co 3d electrons are ferromagnetically ordered on the Co-rich side; the Curie temperature reaches T Co C ≈ 75 K at x = 1 and y = 1. In the Ce-compounds, the Néel temperature T Ce N increases upon suppressing the SDW transition of Fe and then remains nearly unchanged with further increasing Co concentration up to x ≃ 0.8 (T Ce N ≈ 4 K). Furthermore, evidence of Co-induced polarization on Ce-moments is observed on the Co-rich side. In the Gd-compounds, the two magnetic species of Gd and Co are coupled antiferromagnetically to give rise to ferrimagnetic behavior in the magnetic susceptibility on the Co-rich side. For 0.7 ≤ y < 1.0, the system undergoes a possible magnetic reorientation below the Néel temperature of Gd (T Gd N ). Our results suggest that the effects of both electron hybridizations and magnetic exchange coupling between the 3d-4f electrons give rise to a rich phase diagram in the rare-earth iron pnictides. PACS number(s): 74.70. Xa,71.20.Eh,75.20.Hr