In conductors with a very small density of defects, electrons at low temperatures collide predominantly with the edges of a sample. Therefore, the ballistic regime of charge and heat transport is realized. The application of a perpendicular magnetic field substantially modifies the character of ballistic transport. For the case of two-dimensional (2D) electrons in the magnetic fields corresponding to the diameter of the cyclotron trajectories smaller than the sample width a hydrodynamic transport regime is formed. In the latter regime, the flow is mainly controlled by rare electron-electron collisions, which determine the viscosity effect. In this work, we study the ballistic flow of 2D electrons in long samples in magnetic fields up to the critical field of the transition to the hydrodynamic regime. From the solution of the kinetic equation, we obtain analytical formulas for the profiles of the current density and the Hall electric field far and near the ballistic-hydrodynamic transition as well as for the longitudinal and the Hall resistances in these ranges. Our theoretical results, apparently, describe the observed longitudinal resistance of pure graphene samples in the diapason of magnetic fields below the ballistic-hydrodynamic transition.