Added R implementation
All three versions working