We learned about the differences for matrices and data frames in week 3. I was already familiar with data frames from my work, and did not realize the two were different. I am so used to just importing csv files made in Microsoft Excel that I never stopped to think about the inner workings on how R processes these things.
Our assignment this week was was to enter a small data set polling results from two news agencies for seven of the major US presidential candidates from last year and do some converting from matrix to data frame to generate some numbers and graphs.
name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie")
| |||
I used the cbind function to combine the individual name and result columns.
results <- cbind(name, abc, nbc)
I used the data.frame function to change it from a matrix to a data frame:
results <- as.data.frame(results)
We can then run summary statistics by calling the apply function as such
results <- apply(poll.df[,2:3], 2, mean)
abc nbc
24.14286 27.14286
apply(poll.matrix,2,sd)
abc nbc
23.26248 24.57932
I used the supplied ggplot function but had some errors. I played around with it on my own to generate this.
ggplot2 has a lot more functionality than the builtin plot/barplot, which I am used to. These two work well for functions in biology, since those graphs are often very barebones. I am excited to learn more about data visualization.
No comments:
Post a Comment