Step 1: Treating books of each subject as a block.
Since the books of each subject are to be kept together, we can treat each subject as a single block. So, we have 3 blocks: one for History, one for Philosophy, and one for Economics.
Step 2: Arranging the blocks.
The number of ways to arrange these 3 blocks is \( 3! \).
Step 3: Arranging the books within each block.
- The 2 History books can be arranged in \( 2! \) ways.
- The 3 Philosophy books can be arranged in \( 3! \) ways.
- The 5 Economics books can be arranged in \( 5! \) ways.
Step 4: Total number of arrangements.
The total number of arrangements is:
\[
3! \times 2! \times 3! \times 5! = 6 \times 2 \times 6 \times 120 = 8640
\]
Step 5: Conclusion.
Therefore, the correct answer is (4) 8640.