Minor improvement: make sure that the output results consistent

Make sure that the output results of R and SQL are consistent with each
other (have the same number of items)