Posts

Assignment #12: Introduction to R Markdown

Image
  What I learned about Markdown syntax is that it is well organized, and it adds to your code, making it easier to read and cleaner to look at. I learned that LaTeX lets you write out math symbols and equations, making it look neat. The code chunks let me run R inside the same documents, and I did not have a problem. When it came to knitting, I was confused about what it was at first and how to do it but then I found out it just creates the final document..

Assignment #11: Debugging and Defensive Programming in R

Image
 This is the original error code: In the original error there is an extra "&", so there only needs to be one. Having && tests the first true/false value while having & test each element one by one. But there is still an error in which we have not created the tukey.outlier.  To fix this error tukey.oulier needs to be created because the original code calls it, but it is not shown.

Assignment #10: Building Your Own R Package

Image
  The Friedman package is a practice package I used to understand how to build my own R package. It helped me learn how to make an R package, document it, and edit its files. This package is mainly for getting comfortable with creating and organizing packages. I included a simple function called hello() that prints a greeting message. I chose the fields in the DESCRIPTION file to make the package description more detailed and easier to understand. For example, I included my name, the R version it runs on, and a short description explaining its purpose.

Assignment #9: Visualization in R – Base Graphics, Lattice, and ggplot2

Image
  Base R is for basic functions like plot and histogram. The base function is the simplest compared to the others as it creates a quick graph like plot(x, y). While Lattice and ggplot2 are more difficult and more customizable. Lattice is more complicated as it shows different groups using xyplot(y ~ x | group). Then there is ggplot2 where you keep adding on to it with + and start with ggplot(data, aes(x, y)). I believe ggplot2 gave me the most control and made the nicest-looking graph that was more colorful than the others. It looks cleaner and nicer compared to the base and lattice.  It was confusing to switch between the three because they all have different starting codes for example base you just use plot(x, y) and lattice you have to use xyplot(y ~ x | group) and ggplot2 you start with ggplot(data, aes(x, y)) and some of them are harder to read and remember.

Assignment #8: Input/Output, String Manipulation, and the plyr Package

Image
  student <- read.csv(file.choose(), stringsAsFactors = FALSE), reads the file and saves it as a data frame which I named it student. This lets R load in the dataset so we can work with it. library(ply) uses the plyr package, which includes functions for grouping and summarizing data. I need plyr to calculate the avg grade for each gender gorup. gender_mean <- ddply(student, .(Sex), summarise, GradeAverage = mean(Grade, na.rm = TRUE)), takes the student data and groups it with "Sex" and calculates the average of the grade for each group and saves it to gender_mean. The next line saves the the result to a file names gender_mean.txt i_students <- subset(student, grepl("i", Name, ignore.case = TRUE)), looks at all the names and takes in names that have "i" in it and group it to a new dataset called i_students. write.csv(i_students, "i_students_full.csv", row.names = FALSE), saves the data we made earlier with students that have the letter i...

Assignment #7: Exploring R’s Object Oriented Systems (S3 & S4)

Image
 You can tell if it's S3 or S4 by checking its class. S3 objects are usually lists with a class name added, while S4 objects have to be defined first using setClass(). You can tell the class of an object by using class(). When using that on S3 it prints out "students_s3" and the class of S4 is "student_s4" as they are custom classes. A generic function in R is summary(), which displays stats of the data frame and the average. Differences between S3 and S4 are that S3 is simpler, where you make a list and give it a class name, while S4 is more strict, where you have to define the class first and say what data type goes inside. 

Assignment #6: Matrix Operations and Construction

Image
  1.)  A <- matrix(c(2, 0, 1, 3), ncol = 2) and B <- matrix(c(5, 2, 4, -1), ncol = 2) , ncol = 2 to tell r to create a matrix with 2 columns and fill the numbers in with "c()". A + B adds the numbers in that same spot,  for example the first numbers 1,1 is 2 and 5 = 7 because you are adding. A - B subtracts the numbers in that same spot, for example the first numbers 1,1 is 2 and 5 = -3 because you are subtracting. D <- diag(c(4, 1, 2, 3,)) creates a diagonal matrix where numbers go from top left to bottom right. So its telling R to create a matrix and put 4, 1, 2, 3 in a diagonal.  E <- cbind(c(3, 2, 2, 2, 2), diag(3, 5, 5)[,2:5]) this code tells R to create a diagonal with 3's in a 5x5 with diag(3, 5, 5) and [,2:5] is getting rid of the first column and keeping columns 2 through 5. What cbind does it combine the custom column which is (3, 2, 2, 2, 2) in front of the 2-5 columns we kept.