I can't get out of this:

Let's say I have

```
X   Z
2   1
NA  1
3   1
4   2
NA  2
2   2
30  3
30  3
NA  3
30  3

```

I want to replace the NAs in column X with the mean of the X value for the Xs that have the same value of Z. So I would get

```
X   Z
2   1
2.5 1
3   1
4   2
3   2
2   2
30  3
30  3
30  3
30  3

```

Because mean of X for Z=1 is 2.5,mean of X for Z=2 is 3 and mean of X for Z=3 is 30.

I'm sure there should be an easy way to do this :)

Thanks!
Luis.