"More X than you can shake a stick at" means more than you can count. I don't know the origin but a as a wild speculation picture someone using a walking stick or cane to count something. If there's lots to count, the stick will be shaking a lot for each item. If there's too much, the shaking stick won't be able to keep up.
The OED says it's a figurative use of shake but doesn't give any more on the origin other than saying it's colloquial, originally and chiefly U.S., and giving the same 1818 as in the question.
It's originally North American, but it is now commonly used and understood in the UK as well.
I found an earlier example from 1794, but without the comparative "more X than...". British Synonymy: or, An Attempt at Regulating the Choice of Words in Familiar Conversation, Volume 2 by Hester Lynch Piozzi:
THE explanation here is necessary, because the two last verbs are of an active signification, and often used as such ; to shake a stick at you for example, or shiver the glasses all to pieces ; in such sense they are not synonymous with the three first.
But this is British and the full phrase appears to be American, so they may be unconnected.
World Wide Words is usually a good source on these things. If they summarise: "nobody knows for sure", then that's probably the best we have.
However, there is this from alt.english.usage FAQ that questions whether the original meaning was different to today's:
This 19th-century Americanism now means "an abundance"; but its
original meaning is unclear. Suggestions have included "more than one
can count" (OED, AHD3), "more than one can threaten" (Charles Earle
Funk), and "more than one can believe" (Dictionary of American
English). No one of these seems easy to reconcile with all the
following citations: "We have in Lancaster as many taverns as you can
shake a stick at." (1818) "This was a temperance house, and there was
nothing to treat a friend to that was worth shaking a stick at."
(David Crockett, "Tour to the North and Down East", 1835) "Our queen
snake was [...] retiring, attended by more of her subjects than we
even dared to shake a stick at." (1843) "I have never sot eyes on
anything that could shake a stick at that." (= "set eyes on anything
that could compare with that", 1843) "[...] Uncle Sam [...] has more
acres than you can throw a stick at." (1851) "She got onto the
whappiest, biggest, rustiest yaller moccasin that ever you shuck er
stick at." (1851)
A connection with the British expression "hold (the) sticks with",
meaning "compete on equal terms with" and attested since 1817, is not
OED staff told me: "The US usages in DAE do appear to have a different
sense to that given in OED. [...] All the modern examples I've found
on our databases conform to OED's definition so I think this is still
the most common usage."
Merriam-Webster staff opined that the "count" interpretation "works as
well for 'as many as you can shake a stick at' [...] if you take it to
mean that there is no limit to how many of the objects in question one
could shake one's stick at. [...] We would consider 'A can't shake a
stick at B' a different expression entirely, with a meaning similar to
'A can't hold a candle to B' [...]."
In their 1897 work "A Dictionary of Slang, Jargon & Cant", Albert
Barrere and Charles Leland suggested that Dutch immigrants originated
the expression using the Dutch word "schok" = "to shake or hit."