If f(x) varies directly with x, that mean there exists some unknown number k such that f(x) = kx.
So we were given that f(x) = 18 when x = 2. So plugging in these values will help you find the value of k.
18 = 2k
k = 9
So we know that k=9, therefore f(x) = 9x.
Now, at x=6, you have f(6) = 9·6 = 54
Therefore answer is D.