# Back by popular (i.e., Wyatt's) demand

19 Feb 2018I will re-start summarizing the big picture ideas discussed in class. Below a brief recap:

The code we produced in the last three class periods can be downloaded and reviewed here:

### Day 07

We discussed indexing both by location and by logical conditions:

```
x <- c(2, 4, 16)
x[2:3] # extracts the 2nd and 3rd element of x
x[x < 5] # extracts the 1st and 2nd element of x
```

New functions we considered included `print()`

, `paste(..., sep = "")`

, and `cat()`

. We also learned about the modulo operator `%%`

as well as the escape charcter `\`

and the linebreal `"\n"`

.

Another useful new function was `subset()`

.

```
x <- c(3, 2, 1, 0, -1, -2, -3)
subset(x, x > 0) # extracts from x all x greater than zero
```

Finally, we introduced the notion of factors (i.e., special integer type vectors with the attribute factor and levels).

```
x <- c("yes", "yes", "no")
x <- as.factor(x)
x
typeof(x)
summary(x)
```

### Day 08

New functions include `is.na()`

to querry `NA`

s and `na.omit()`

to subset objects such that `NA`

s are excluded. Also discussed:

`source("C:/Users/Username/Desktop/SomeCode.R")`

– to execute all code in a file`data.frame()`

– a function equivalent to`c()`

to join vectors together into a data frame`$`

– notation to extract vectors from data frames e.g.,`frame$vector`

extracts the vector named vector from the data frame called frame`write.csv(xyz, "C:\Users\Username\Desktop\XYZ.csv")`

– writes object to a comma-separated value (`.csv`

) file`xyz <- read.csv("C:\Users\Username\Desktop\XYZ.csv")`

– reads such a file into R

### Day 09

Functions discussed included:

`str()`

to describe the structure of an object`summary()`

basic summary statistics of an object`describe()`

more detailed summary statistics via “Hmisc” package`names()`

names of vectors stored in data frame`head()`

and`tail()`

get the first and last few rows of a data frame, respectively`ifelse()`

basic if-else construct

More complicated flow control:

```
if (1 + 1 == 2) {print("True")} else {print("False")}
if (0.5 > 1) {
x <- rnorm(10)
x[1]
sum(x)
} else {
y <- runif(10, 0, 1)
y[1]
sum(y)
}
```