Gandalf was always something of a playful trickster, coming and going in the novels, and really, ambushing Bilbo into the mission to the Lonely Mountain. He was mischievous, and apt to vanish, then pop up just when he was needed. The vanishing act shows up in both films, but the mischievous side was better portrayed in The Hobbit; the Gandalf of Lord of the Rings is a more thoughtful, calculated character. Gandalf in the Hobbit was perfectly willing to hijack the life of a total stranger, on little more than a whim, and send him on his way. It owes a lot to the source material, of course, but it's a more rounded Gandalf.