If primary cosmic rays are made mostly of protons, where are the electrons lost, and does this mean that the Earth is positively charged? Does the sun eject protons and electrons in equal number?
Great question. The electric field creates such a strong force that it would be very hard to move large amounts of just one type of charge. So astrophysical systems do generally eject equal numbers of protons and electrons. In particular, the solar wind is electrically neutral. So these cosmic rays are created in very nearly equal numbers, but by the time they get to Earth, there are far fewer electrons.
The main interaction that causes these electrons to get "lost" is inverse Compton scattering. What happens is that the electrons traveling between galaxies interact with the cosmic microwave background and lose most of their energy -- basically they bounce off of photons. This is where most of the electrons in cosmic rays are lost, which means that all the cosmic-ray electrons at earth will come from inside our galaxy. Of course, the scattering happens for protons and heavier ions, too, but it's far weaker for them. (The rate of energy loss is inversely proportional to mass, and protons and other ions are far heavier than electrons.)
As for net charges, there are still lots of open questions. But basically, if we accumulate much charge, we will soon attract a lot of the opposite type of charge, and become neutral again. So we don't think the Earth has much of a net charge, though I don't know of any precise limits.