Posts

Assignment #12: Introduction to R Markdown

Image
 R markdown is a fairly interesting idea in concept. The whole Latex system took a bit of research to figure out, and I only used a very small portion of what its capable of. You can easily setup the narrative and code sections of an R markdown document to prepare an easy to follow presentation.  As shown you can add code and run it similar to how the output to html is. The code and immediate output is woven into the document.  code repository can be found at: https://github.com/Wrightkov/r-programming-assignments

Assignment 11

 Today's lesson is in debugging. we were given the code: tukey.outlier <- function(x, k = 1.5) {   q1 <- quantile(x, 0.25, na.rm = TRUE)   q3 <- quantile(x, 0.75, na.rm = TRUE)   iqr <- q3 - q1   x < (q1 - k * iqr) | x > (q3 + k * iqr) } tukey_multiple <- function(x) {   outliers <- array(TRUE, dim = dim(x))   for (j in 1:ncol(x)) {     outliers[, j] <- outliers[, j] && tukey.outlier(x[, j])   }   outlier.vec <- vector("logical", length = nrow(x))   for (i in 1:nrow(x)) {     outlier.vec[i] <- all(outliers[i, ])   }   return(outlier.vec) Error in outliers[, j] && tukey.outlier(x[, j]) : 'length = 10' in coercion to 'logical(1) when run with a seed it gives this error, this happens because this only evaluates the first element in each vector. A fully corrected and debugged version of the code can be found here. This replaces the broken && code and t...

Assignment #10: Building Your Own R Package

The purpose of my blog this week is to build a  draft a proposal describing: The purpose and scope of your package (who will use it and why). The idea would be for small businesses to quickly sort and predict where volume of orders are being shipped most often. Key functions you plan to implement (name + brief description). clean address sort labels by region determine where most your key shipping locations are. How you chose the fields in  DESCRIPTION  (dependencies, license, authors). Package: Friedman Title: What the Package Does (One Line, Title Case) Version: 0.0.0.9000 Authors@R:      person("Zachary", "Wright", , "zakkwright@yahoo.com", role = c("aut", "cre")) Description: "Tools for organizing and analyzing shipping and order data for small collectible businesses.  With the intention of " License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a     license Encoding: UTF-8 Roxygen: list(markdown = TRUE...
Image
 This week's assignment was to make visualizations in three different ways in R.  I chose a humorous Beenie baby dataset to work with from the list chosen that is based around the age of the Beenie and its current price.   Dataset can be located here: https://vincentarelbundock.github.io/Rdatasets/datasets.html My first 2 plots were simple plots using built in R commands: plot(beanie$age, beanie$value,      main = "Beanie Value vs Age",      xlab = "Age",      ylab = "Value") hist(beanie$value,      main = "Distribution of Beanie Values",      xlab = "Value") Next I was told to make a plot using "lattice"  xyplot(value ~ age, data = beanie,        main = "Value vs Age",        xlab = "Age",        ylab = "Value",        col = "blue") bwplot(age ~ value, data = beanie,        main = "Value b...

Module # 8 Input/Output, string manipulation and plyr package

 This week was all about manipulating a file and outputting a new one.  Starting with I imported Plyr, this will be used to manipulate the data. library(plyr) I then imported the file that was given to us and did the first use of dply with ddply. Student_assignment_6 <- read.csv("Assignment 6 Dataset.txt", header = TRUE) StudentAverage <- ddply(Student_assignment_6, "Sex", transform,                         Grade.Average = mean(Grade)) print(StudentAverage) I know that dpplyr should have a way to do this next step but I struggled with it a bit and just split it for my own sake. mean_male <- mean(Student_assignment_6$Grade[Student_assignment_6$Sex == "Male"]) mean_female <- mean(Student_assignment_6$Grade[Student_assignment_6$Sex == "Female"]) I then used Grep command to make a subset of people with I in their name. In order to get both upper and lower I used [iI] so it read both i_students <- subset(Stu...

Module # 7 R Object: S3 vs. S4 assignment

  How do you tell what OO system (S3 vs. S4) an object is associated with?          Y ou can check an Objects class using  class(object_name) in order to determine if its S3 or S4. If an object has a formal class definition then it is S4. Most base R objects are S3 How do you determine the base type (like integer or list) of an object? You can use the command typeof() in order to get a readout of what type an object is. For instance class(mtcars) will give you a readout "data.frame" but typeof(mtcars) will give you the base type list.  What is a generic function? A generic function is a function that performs differently depending on the class. R actually decides what the function does for you in a process called method dispatch. methods() will list all the options the function could perform some examples of generics print() summary() plot() mean() head() tail() str() What are the main differences between S3 and S4? S3 is a simple and informa...

Module # 6 Doing math in R part 2

Image
 This week was more on matrixes in R.  For step one we had to make 2 matrixes and then add and subtract them. A = matrix(c(2,0,1,3), ncol=2) B = matrix(c(5,2,4,-1), ncol=2) A + B A - B                                                       Next I was instructed to make a matrix " matrix of size 4 with the following values in the diagonal 4,1,2,3." matrix1 <- diag(c(4, 1, 2, 3))  Finally I was asked to make a very specific matrix using Diag M <- diag(3, 5) M[1, ] <- c(3, 1, 1, 1, 1) M[2:5, 1] <- 2