Keep in mind too, that not all "battles" took place on a battlefield. Many times daggers were used as a sneak attack, in dark alleys, ports, taverns, etc.
For example... a "knight" has gone to his local tavern and happens to be relaxing with a pint or twenty. Some nefarious person comes up behind him and notices a fat purse and decides to take it. They probably aren't going to pull out their giant battle axe and give a war cry to alert the poor stupid knight and everyone else in the tavern. No, they are going to pretend to be drunk, stumble over, shank him in the side with his dagger of doom, piercing the armor he most likely didn't take off, and steal the purse, before stumbling out the door. No one being the wiser of what he did until they find the knight's bleeding body at closing time.
Now, let's say Mr. Nefarious doesn't kill the knight... If the knight gets up and starts chasing the thief, does it make sense for the thief to not be able to defend himself atall? No. He would have skills, and would be deadly with his daggers. Otherwise he would have chosen another line of work.
And yes, soldiers did carry daggers... as secondary weapons. No one ever charged into battle holding their bright, shiny (read that as tiny compared to a claymore) dagger aloft. No, you kept it in a boot, or a sheath in case your primary weapon was lost, damaged, or you were too injured to lift it.
P.S. Depends on the years of training for both the ninja and the samurai.
P.S.S. Ninja were trained in the use of many weapons, quite a few being very effective on a long range distance which a samurai could not compensate for. Don't forget shuriken and the like. Katana and wakazashi were not ideal weapons for ninja, as they generally involved being close or visible.
P.S.S. Honestly, the style of combat seen in Eastern cultures is so different than that of Western cultures that its hard to compare them. Huge cumbersome weapons, versus light, fast ones. Even the smallest true double-edged sword lacks the precise handling of a katana. But, this also takes into consideration the overall musculature and stature of those wielding them.