Saturday, February 27, 2016

Module 7 : R Objects

I came into this week feeling very optimistic about the coursework, due in large part to the fact that I’m familiar with object oriented programming from C++ and Java courses in past semesters. This doesn’t make the assignment any less challenging, mind you, but at least I have a more firm grasp on these concepts and can hit the ground running, so to speak. On to the assignment!

I chose to use a dataset called “discoveries” from the datasets package that consists of the yearly numbers of important discoveries from 1860 to 1959:


The bass type of the 'discoveries' object is double, and this is easily determined by typeof(discoveries). I also tried some other datasets in my environment that were defined as integers and typeof(a) (for example) confirmed that.

The second step in our assignment addressed generic functions which are functions that dispatch methods of a generic concept. Examples of generic functions in R include plot, mean, residuals, predict, summary and others. I chose to determine whether a generic function could be assigned to my "discoveries" dataset by using the plot function, plot(discoveries):


I also attempted some others such as summaries(discoveries):



I had success with a variety of generic functions, but I also tried plenty that did not work, such as logLik and predict which returned errors stating:

Error in UseMethod("predict/logLik") :
  no applicable method for 'predict/logLik' applied to an object of class "ts"

The final step of the assignment is to determine whether S3 or S4 can be assigned to the dataset I chose. S3 and S4 are two object systems that are used in the R programming language. S3 objects are informal and more interactive than S4 which are more rigorous. The way to determine whether S3 or S4 can be assigned to a dataset is by using the S4() function. For example, S4(experiences) returns false which means that S3 can be applied. 

No comments:

Post a Comment