summaryrefslogtreecommitdiffhomepage
path: root/r.html.markdown
diff options
context:
space:
mode:
authorLeah Hanson <astrieanna@gmail.com>2013-07-01 18:10:18 -0400
committerLeah Hanson <astrieanna@gmail.com>2013-07-01 18:10:18 -0400
commit759753cb5b5e6b0d26dc675bd1f704bc5fe331a9 (patch)
treecfb6fa2ce89aafc8814cdeb9f5a2ce025badd7e7 /r.html.markdown
parent7b21a8ae1bdd909b9923290f588ffae17ea960a5 (diff)
parent87670d3bb63f96c65a105824fce4f85f4ef0f845 (diff)
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
Diffstat (limited to 'r.html.markdown')
-rw-r--r--r.html.markdown34
1 files changed, 17 insertions, 17 deletions
diff --git a/r.html.markdown b/r.html.markdown
index ad2a4559..38317776 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -2,12 +2,12 @@
language: R
author: e99n09
author_url: http://github.com/e99n09
-
+filename: learnr.r
---
R is a statistical computing language.
-```r
+```python
# Comments start with hashtags.
@@ -16,9 +16,9 @@ R is a statistical computing language.
# Protip: hit COMMAND-ENTER to execute a line
-###################################################################################
+#########################
# The absolute basics
-###################################################################################
+#########################
# NUMERICS
@@ -119,9 +119,9 @@ myFunc <- function(x) {
# Called like any other R function:
myFunc(5) # => [1] 19
-###################################################################################
+#########################
# Fun with data: vectors, matrices, data frames, and arrays
-###################################################################################
+#########################
# ONE-DIMENSIONAL
@@ -130,7 +130,7 @@ vec <- c(4, 5, 6, 7)
vec # => [1] 4 5 6 7
# The class of a vector is the class of its components
class(vec) # => [1] "numeric"
-# If you vectorize items of different classes, weird coersions happen
+# If you vectorize items of different classes, weird coercions happen
c(TRUE, 4) # => [1] 1 4
c("dog", TRUE, 4) # => [1] "dog" "TRUE" "4"
@@ -192,7 +192,7 @@ mat3
# [,1] [,2] [,3] [,4]
# [1,] 1 2 4 5
# [2,] 6 7 0 4
-# Aah, everything of the same class. No coersions. Much better.
+# Aah, everything of the same class. No coercions. Much better.
# TWO-DIMENSIONAL (DIFFERENT CLASSES)
@@ -243,7 +243,7 @@ array(c(c(c(2,300,4),c(8,9,0)),c(c(5,60,0),c(66,7,847))), dim=c(3,2,2))
# LISTS (MULTI-DIMENSIONAL, POSSIBLY RAGGED, OF DIFFERENT TYPES)
# Finally, R has lists (of vectors)
-list1 <- list(time = 1:40, price = c(rnorm(40,.5*list1$time,4))) # generate random
+list1 <- list(time = 1:40, price = c(rnorm(40,.5*list1$time,4))) # random
list1
# You can get items in the list like so
@@ -251,9 +251,9 @@ list1$time
# You can subset list items like vectors
list1$price[4]
-###################################################################################
+#########################
# The apply() family of functions
-###################################################################################
+#########################
# Remember mat?
mat
@@ -273,7 +273,7 @@ apply(mat, MAR = 2, myFunc)
# [2,] 7 19
# [3,] 11 23
# Other functions: ?lapply, ?sapply
-# Don't feel too intimiated; everyone agrees they are rather confusing
+# Don't feel too intimidated; everyone agrees they are rather confusing
# The plyr package aims to replace (and improve upon!) the *apply() family.
@@ -281,9 +281,9 @@ install.packages("plyr")
require(plyr)
?plyr
-###################################################################################
+#########################
# Loading data
-###################################################################################
+#########################
# "pets.csv" is a file on the internet
pets <- read.csv("http://learnxinyminutes.com/docs/pets.csv")
@@ -292,14 +292,14 @@ head(pets, 2) # first two rows
tail(pets, 1) # last row
# To save a data frame or matrix as a .csv file
-write.csv(pets, "pets2.csv") # to make a new .csv file in the working directory
+write.csv(pets, "pets2.csv") # to make a new .csv file
# set working directory with setwd(), look it up with getwd()
# Try ?read.csv and ?write.csv for more information
-###################################################################################
+#########################
# Plots
-###################################################################################
+#########################
# Scatterplots!
plot(list1$time, list1$price, main = "fake data")