summarizeRows function

Summarizing rows/columns by a factor