finished r data manipulation