finished R assignment

code finalised