---
title: "R Lecture 1"
output: html_notebook
---

Let's run the following chunks of code and see what they do! 


The following initializes a variable as NULL which is like a blank placeholder.
```{r}
y<-NULL
```

```{r}
y
```


Here I assign the value 5 to the variable y:
```{r}
y<-5
```

```{r}
y
```


Here are some boolean assignments. 
```{r}
x<-TRUE
z<-FALSE
```


```{r}
x
z
```

We can use boolean connectives like "&" or "&&" (AND), "|" or ||" (OR), and "!" (Negation)

```{r}
x&z
z||x
!x
```



You can test whether a variable is of a given type with functions like "is.logical()", "is.numeric()", "is.na()", "is.factor()"

```{r}
is.logical(x)
is.logical(y)
is.numeric(y)
```



Here, I create a vector called "greg_vect"
```{r}
greg_vect<-c(1,1,2,3,5,8,13, 21, 34, 55)
```


```{r}
greg_vect
```


```{r}
test_vect<-c(1,2,3,4,5)
test_vect
```


Here, I create a new data frame by reading in a .csv file:

```{r}
gregs_df<-read.csv("example.csv")
gregs_df
```

View the top few rows of a dataframe with "head()"
```{r}
head(gregs_df)
```

```{r}
gregs_df$Random.number.1
```



Indexing vectors: 

```{r}
greg_vect[1:4]
```


Here we create a boolean vector which is true wherever greg_vect is even. 
```{r}
even<-greg_vect%%2==0
even

length(even)
```

Now, we can return the entries of greg_vect that are even: 

```{r}
greg_vect[even]
```

```{r}
odd<-greg_vect%%2==1
odd
```
```{r}
greg_vect[odd]
```


```{r}
greg_vect[greg_vect>5]
```



Some operations on numbers:

```{r}
2*5
2+5
2^5
log(42)
129389873287%%42 

log(2+3*(4+8)^42)
```

Some operations on vectors:

```{r}
length(greg_vect)
```
```{r}
sum(greg_vect)
```
```{r}
prod(greg_vect)
```


Let's make a stem and leaf plot (note: the $ let's me select a specific column from my data frame): 

```{r}
stem(gregs_df$Random.number.1)
```
That's interesting... pretty even... WHY? (Hint: I used Excel's RAND() function).

```{r}
hist(greg_vect, breaks = 100)
```


```{r}
hist(gregs_df$Random.number.1,breaks = 1000)
```


Box Plots: 


```{r}
boxplot(gregs_df$Random.number.2)
```


Make a scatter plot: 

```{r}
plot(x=gregs_df$Random.Number.3,y=gregs_df$Random.Number.4, xlab = "More stuff", ylab = "Other stuff")
title("Stuff")
```


```{r}
summary(gregs_df$Random.number.1)
```



```{r}

factortable<-table(gregs_df$The.best.people)
factortable
```



```{r}
mean(greg_vect)
```



```{r}
summary(gregs_df$Random.number.1)
```

```{r}
fivenum((gregs_df$Random.number.2))
```


```{r}
barplot(factortable)
title("The best People")
```


```{r}
pie(factortable)
```



```{r}
head(gregs_df)
```







```{r}
test2<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20)
```


```{r}
pairity<-test2%%2
pairity
```













