Posts

Assignment 11: Debugging and defensive programming in R

Image
 Assignment 11: Debugging and defensive programming in R     This week was interesting because we were given the code we needed and were tasked with fixing the error(/s) that was(/were) present. First though we needed to run the program so that the system itself could aid in our diagnosis of the issue which can be seen below:      Here we can see that with the addition of the second & sign made the logic of the program attempt to only evaluate the first element of each vector, which is not what is needed. Further, && is usually used with if statements or while loops whereas the single & is used for vector or matrix operations. The correction with the single & results in the program checking each row independently, fixing the previous logical error, seen below:     The above is the corrected code with the proper number of ampersands. Unlike the first set of code, we can see an output instead of an error message, and each row has...

Assignment 10: Building my own R package

Image
 Assignment 10: Building my own R package I've spent a lot of time this week trying to accomplish the skeleton of the r package, but I am unable to get the git commands to work. Not sure why, seems like I've downloaded gigabytes of packages and other miscellaneous programs and yet in the terminal when I attempt to use git commands to commit it to the GitHub branch I fail.  My description can be seen above, this is a temporary loss, I have work at 9 am and it is now nearing 11pm, unfortunately I didn't allocate enough time today to completing this assignment, and I didn't realize how ill-prepared I was for the task itself. Seeing as this is something I need for my final project, not completing it in its entirety simply won't do, so for now I must submit just what I have available, and Tuesday when I don't have any commitments, I will resubmit this in its complete form. I apologize for my shortcomings here. As for my plan. I am a stock trader, actually a derivativ...

Assignment 9: Visualization in Base R, Lattice and ggplot2

Image
 Assignment 9: Visualization in Base R, Lattice and ggplot2      This assignment we were tasked with selecting a dataset within the provided list, which I chose the air quality dataset which I've been given the chance to use in the past in other assignments, and I felt it a good fit for this also  I began by exploring the dataset and I realized that if I wanted to do a timeseries plot for the lattice graph I had to reformat the data to add in the year, which I found exploring the data with "?airquality". The entirety of the code is available on my GitHub here, and t he code of all 3 graphs is shown here: The first graph using base R was simple and shown here:     This graph is showing the ozone level during the summer of 1973. An issue I found when creating this first graph was that the dataset had a large number of large gaps, and I dealt with this issue by just removing the NA values of the dataset and storing this all in a new variable airClean. I ...

Week 8: Input/Output, string manipulation and plyr package

Image
Week 8: Input/output, string manipulation and plyr package     This week was interesting, and the concepts covered within were quite complex this week, seeing code I've never seen before to alter csv files in ways I haven't had the chance to. I had issues downloading the file however, as it didn't wish to save properly, having instead to copy the info into a notepad file, save as all files, and manually type .csv at the end of the file.   However, in the end I got it done, the variable names may be a little wonky as a result, but the code is functional, and I will explain line by line what is going on. The code is available on my GitHub here , and I will upload the csv also. This is the first few lines of my program, with the first two simply reading in necessary libraries for the program to function, the third reading the csv data (file that I created) into the variable assignment8dataset and then we group the dataset by "sex" (gender), calculate the average grad...

Module 7: Object S3 vs S4

Image
 Module 7: Object S3 vs S4     This week we learnt about S3 and S4 systems, and I got to play around with a lot of code this week attempting to learn about it and satisfy the homework requirements, which I believe I have done to quite a sufficient level.  First, I created my own dataset, then, explored it using a variety of the generic functions to show it worked as intended. Then, I began with my first S3 addition to my created data frame, followed by my first S4 addition. I then added one more example of each to satisfy the fifth questions need for 2 examples of each and all of it will be available on my github linked here! Now I will answer the questions as they were asked: 1. How do you tell what OO system (S3 vs. S4) an object is associated with?    The easiest way to tackle this question is to explain what both are. An S3 object is informal, a list, data frame, vector with a class attribute attached. S4 objects however are formal, have slots and ...

Week 6: Doing Math pt2

Image
Week 6: Doing Math pt2 This week we covered more matrices and how to use certain functions to manipulate them. R is also already quite handy at dealing with these concepts so without further ado, I will show the entirety of my code, then its outputs in parts where I will explain either what we see, what I did or both. Okay, so now I will show the output for the first 8 lines and discuss: The first 2 lines are simply the copying and creating of the matrices used in this assignment. The first thing we were asked to do was add matrix a and matrix b, so I did just that, and stored the result in a variable called plus, which was then printed. I did the same basic idea but with subtraction for a - b stored in variable minus. I then used the diag command as was suggested by the professor to create the second matrix that was requested by the assignment instructions, storing the result in matrixOne, then printing the result to the screen for confirmation.  The first thing I did to produce t...

Week 5: Doing Math

Image
  Week 5: Doing Math      This week we were tasked with learning about matrices and finding the inverse value and determinant of a matrix using some provided values. I will show my code in parts, explaining as I go along what everything means, as well as what the error codes reveal. This was a fascinating week, and the assignment really makes you think!     The first thing we can see is that A appears to be a 10x10 square matrix, whereas B is not with its dimensions being 10x100. We also see that the determinant of A is 0, which we take to mean that A is singular, and no inverse of it exists.      As I mentioned, A is singular as is confirmed by the error message, and as a result cannot be inverted which is attempted by the solve A command. In other words, it tries to Solve A (invert A) but fails to do so and when not placed in the tryCatch, causes the code to fail without running the rest of the program. We see similar occurrences when we at...