This is an R Markdown Notebook. I love the idea of presenting data analysis as a narrative, where the the process of crunching numbers is documented and celebrated as much as the findings. I have a lot to learn about how notebooks like this one are used within the scientific community to share ideas, but it feels like a format with many possibilities.
I'd like to figure out how to easily style notebooks, without sacrificing their readability and compatibility. For now I just want to learn how to make one, and use it as a tool to learn more about how R works.
First, I’m going to import a dataset on crabs my stat professor used recently to introduce us to R:
crabs = read.table("http://educ.jmu.edu/~chen3lx/math327/crabs.txt", header=T)
Now let's graph the width and weight of the crabs on a scatterplot:
plot(crabs$width,crabs$weight)
I’ve spent a lot of time trying to make pretty SVG graphs on my website in the past, and it would be so cool to do the same interactively with R. Maybe that’ll be my next project.
For the last bit of code in this notebook, I’ll calculate the correlation coefficient for the crabs’ width and height:
cor(crabs$width,crabs$weight)
[1] 0.8868715
They seem to be quite correlated! cool
LS0tDQp0aXRsZTogIkV4cGVyaW1lbnRhbCBSIE5vdGVib29rIg0Kb3V0cHV0OiBodG1sX25vdGVib29rDQotLS0NCg0KVGhpcyBpcyBhbiBbUiBNYXJrZG93bl0oaHR0cDovL3JtYXJrZG93bi5yc3R1ZGlvLmNvbSkgTm90ZWJvb2suIEkgbG92ZSB0aGUgaWRlYSBvZiBwcmVzZW50aW5nIGRhdGEgYW5hbHlzaXMgYXMgYSBuYXJyYXRpdmUsIHdoZXJlIHRoZSB0aGUgcHJvY2VzcyBvZiBjcnVuY2hpbmcgbnVtYmVycyBpcyBkb2N1bWVudGVkIGFuZCBjZWxlYnJhdGVkIGFzIG11Y2ggYXMgdGhlIGZpbmRpbmdzLiBJIGhhdmUgYSBsb3QgdG8gbGVhcm4gYWJvdXQgaG93IG5vdGVib29rcyBsaWtlIHRoaXMgb25lIGFyZSB1c2VkIHdpdGhpbiB0aGUgc2NpZW50aWZpYyBjb21tdW5pdHkgdG8gc2hhcmUgaWRlYXMsIGJ1dCBpdCBmZWVscyBsaWtlIGEgZm9ybWF0IHdpdGggbWFueSBwb3NzaWJpbGl0aWVzLg0KDQpJIGRyZW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