R: Shortening of code