summaryrefslogtreecommitdiffhomepage
path: root/r.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'r.html.markdown')
-rw-r--r--r.html.markdown20
1 files changed, 11 insertions, 9 deletions
diff --git a/r.html.markdown b/r.html.markdown
index dd94072b..03aa1dd2 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -2,6 +2,7 @@
language: R
contributors:
- ["e99n09", "http://github.com/e99n09"]
+ - ["isomorphismes", "http://twitter.com/isomorphisms"]
filename: learnr.r
---
@@ -296,14 +297,13 @@ if (4 > 3) {
# FUNCTIONS
# Defined like so:
-myFunc <- function(x) {
- x <- x * 4
- x <- x - 1
+jiggle <- function(x) {
+ x+ rnorm(x, sd=.1) #add in a bit of (controlled) noise
return(x)
}
# Called like any other R function:
-myFunc(5) # 19
+jiggle(5) # 5±ε. After set.seed(2716057), jiggle(5)==5.005043
#########################
# Fun with data: vectors, matrices, data frames, and arrays
@@ -428,15 +428,17 @@ 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))
# =>
# , , 1
#
-# [,1] [,2]
-# [1,] 1 4
-# [2,] 2 5
+# [,1] [,2]
+# [1,] 2 8
+# [2,] 300 9
+# [3,] 4 0
#
# , , 2
#
# [,1] [,2]
-# [1,] 8 1
-# [2,] 9 2
+# [1,] 5 66
+# [2,] 60 7
+# [3,] 0 847
# LISTS (MULTI-DIMENSIONAL, POSSIBLY RAGGED, OF DIFFERENT TYPES)