Unified SU(4) theory for the RD(*) and RK(*) anomalies