From 3133b22afd2cf4a7eea14c70c7f5de4a9cb4b0e2 Mon Sep 17 00:00:00 2001 From: Alana Schick Date: Wed, 13 Feb 2019 14:06:36 -0700 Subject: [PATCH] add example script to intro to R lesson --- 01-intro-to-R.Rmd | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/01-intro-to-R.Rmd b/01-intro-to-R.Rmd index cacd211..02b94cb 100644 --- a/01-intro-to-R.Rmd +++ b/01-intro-to-R.Rmd @@ -30,9 +30,27 @@ _Start by showing an example of a script_ - the assignment operator `<-` - the `=` for arguments - the comments `#` and how they are used to document function and its content - - the `$` operator * Point to indentation and consistency in spacing to improve clarity +Example script: + +```{r, purl = FALSE} +# This is a comment, R will not read anything following a hashtag + +x <- 6 +y <- 19 +z <- sum(x, y) # This is a function + +# Syntax for an if statement +# If the expression inside the () is true, R will evaluate everything inside the {} +if (z > 10){ + vector <- c(x, y, z) +} + +# Print vector and the length of vector +vector +length(vector) +``` ## Creating objects