R calculation fix