R Markdown


title: “RMark”
output: pdf_document

“`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
“`

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com&gt;.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

“`{r cars}
summary(cars)
“`

## Including Plots

You can also embed plots, for example:

“`{r pressure, echo=FALSE}
plot(pressure)
“`

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Module # 11

At first I tried to call the function with a random set of numbers.
> z <- c(1,4,5,7,3,4,7,8,9,8,9,9,9,8,8,9,9,9)
> tukey_multiple(z)

This gave me an error.

The multiple debugging tests I ran for the function are debug() and traceback() this are the error I got.

Screen Shot 2020-04-03 at 6.09.15 PMScreen Shot 2020-04-05 at 7.00.49 PMScreen Shot 2020-04-03 at 6.09.23 PM

I could not fix the bug in the function.

Visualization in R

 

Data from vincentarelbundock.github.io/Rdatasets/datasets.html. 

 

Screen Shot 2020-03-13 at 1.02.22 PM

 

Visualizations

Screen Shot 2020-03-13 at 12.23.37 PM

This visualization was created using ggplot2. ggplot2 is one of my favorite packages to use in R and I feel comfortable using it. By using ggplot you have a lot of different tools to manipulate your data and making great images that are easy to read and fun to make. In my output I show the minimum price of cars compared to the milage per gallon while driving in the city. I also used geom_point to display the type of cars. This image is easy to read and it provides a lot of information.

 

Screen Shot 2020-03-13 at 12.46.15 PM

This visualization was created using Lattice. Using Lattice was new to me but I found it to be very helpful when displaying data. In a way the Lattice package is similar to ggplot2 when it comes to the freedom of visualizing your data. I was able to create a density plot to show highway miles per gallon.

Screen Shot 2020-03-13 at 12.48.35 PM

This is a basic graphic created from R. I think this is one of the easiest visualization to created when you are not experienced using Lattice or ggplot2. As you can see this image is very simple and may show a lot of information. For some people this may be seen as boring and hard to read.

Module # 8 assignment

Student <- read.table(“Assignment 6 Dataset-1.txt”, header = TRUE, sep = “,”)

sex <- Student$Sex

StudentAverage = ddply(Student,”Sex”,transform,Grade.Average=mean(Grade))

write.table(StudentAverage, “sortedAverage”)

new <- subset(Student, grepl(“i”, Student$Name, ignore.case=T))

OUTPUT

 

Reading the files was an easy task because I have done this before. But some of the functions that were new to me were file.choose() and read line(). Stringsplit was new to me because I have not used this function in R but I have used in other languages.

I find the function subset to be very helpful when sorting the data in order to understand it better.

Module # 7 R Object: S3 vs. S4 assignment

  1. How do you tell what OO system (S3 vs. S4) an object is associated with?To determine the OO system of an object, you use a process of elimination. If !is.object(x), it’s a base object. If !isS4(x), it’s S3. If !is(x, "refClass"), it’s S4; otherwise it’s RC.
  2. How do you determine the base type (like integer or list) of an object?
    Use typeof() to determine the base class of an object.
  3. What is a generic function?
    A generic function calls specific methods depending on the class of it inputs. In S3 and S4 object systems, methods belong to generic functions, not classes like in other programming languages.
  4. What are the main differences between S3 and S4?
    S4 is more formal than S3, and supports multiple inheritance and multiple dispatch. RC objects have reference semantics, and methods belong to classes, not functions.

Genetic Function with USArrest data set.

 

Plot(USArrest)

Screen Shot 2020-03-01 at 2.44.11 PM

Module # 3 Introduction to data.frame

Code:

Name <- c(“Jeb”, “Donald”, “Ted”, “Marco”, “Carly”, “Hillary”, “Bernie”)
ABCresults <- c(4,62,51,21,2,14,15)
CBSresults <- c(12,75,43,19,1,21,19)

ABCmatrix <- matrix(ABCresults, byrow = T)
ABCmatrix

matrix <- matrix(ABCresults,CBSresults,Name)
df <- data.frame(Name, ABCresults, CBSresults)
df

 

Results:

Screen Shot 2020-02-02 at 12.30.28 PM

 

As show, with this data you can not create a matrix because of the character values in the data.
If a matrix was created with just numerical values, it creates a matrix.

For this data a data frame is a better way to display the data.