Is it considered poor practice to take a suggestion made by a vague (but objectively correct) answer, expand upon it, and then accept your own answer?
It's generally fine, as long as you write a real answer and not just a code dump of what worked for you. Accepted self-answers aren't pinned to the top across Stack Exchange sites (even before we recently unpinned all accepted answers on SO). That means community voting can decide on the relative value of the answers, so for example if a beginner just learning a language does this and accepts their answer with code containing a bunch of clunky stuff, and the other answer was good and general, the voting may favour the more vague but general answer. (Especially if there are any actual bugs; comments can point them out.)
In this case specifically, the earlier answer is pretty low effort, just a link to the docs for some function / command and quoting a few relevant portions of it. That's a helpful pointer, but just barely enough to not be a link-only answer.
You don't need to worry about stepping on that answer's toes: whoever wrote it wanted to point you in the right direction, but not put in the time to actually solve the full problem you were asking about. You did, and an answer to that question is the right place to share the results for the benefit of future readers. (And yes, you can accept it if you think it's going to be more helpful to future readers than the other answer. Or just because it's what worked for you.)
In general, your answer can cite the answer that pointed you in the right direction, as a way of giving the answerer credit. That's a good thing.
Working examples of how to use functions / commands / whatever are not a bad thing to have on SO, so there is added value in having a worked-out answer.
Editing the question?
Probably don't do that. The real problem you're trying to solve is implied by the overall question, so your answer is still an answer to the question, not broadening it to something else.
An edit to specifically ask for how to actually use such a command, instead of just asking for its name, would invalidate the existing answer so I wouldn't recommend that.
You can (and have) achieved the best thing for everyone (working code as an answer) without stepping on any toes by invalidating an existing answer. I think what you did was the optimal thing.
(Huge caveat: I haven't looked in any detail at the question or your answer because it's a language and subject I don't know. I'm just assuming the answer is useful to future readers. If not, though, it's still 100% possible for voting to decide that, since the actions taken here haven't interfered with that.)
You also don't need a new question cluttering up SO with 2 questions linked to each other that are very close followups.