## -----------------------------------------------------------------------------
4 + 6 - (24/6)
(6 - 4) * 3
5 ^ 2


## -----------------------------------------------------------------------------
# Example of a comment. This line does NOT get run by the program. 


## -----------------------------------------------------------------------------
exp(2) # This is the number e raised to the power within the parentheses
sqrt(4) # Square root
abs(-5) # Absolute value


## -----------------------------------------------------------------------------
x <- 5 # This assigns the value 5 to the variable x.
# Now we can reference x, and R substitutes in 5.
x
# This is useful for things like 
y <- log(5) + 3/2 # "log" in R is natural log (ln)
y


## -----------------------------------------------------------------------------
x <- 2 + 5
x
x <- x + 5
x
x <- y + 5
x


## -----------------------------------------------------------------------------
X <- 3 # uppercase X
x <- 6 # lowercase x
X
x


## -----------------------------------------------------------------------------
lab1 <- read.delim('https://raw.githubusercontent.com/IowaBiostat/data-sets/main/tips/tips.txt')


## -----------------------------------------------------------------------------
head(lab1) # Outputs only the first few lines of a dataset
summary(lab1) # Gives summary statistics for the dataset


## -----------------------------------------------------------------------------
#    dataset$variable
tips <- lab1$Tip
head(tips)


## -----------------------------------------------------------------------------
max(tips) # Largest Tip


## -----------------------------------------------------------------------------
total <- lab1$TotBill
head(total) # print out the first few values


## -----------------------------------------------------------------------------
#| eval: false

# ?sort # look up the help documentation for 'sort'

## -----------------------------------------------------------------------------
total_sorted <- sort(total, decreasing = TRUE)
# note the new vector appears in your environment under "values"


## -----------------------------------------------------------------------------
mean(total)


## -----------------------------------------------------------------------------
log_tip <- log(lab1$Tip)
mean(log_tip)
sd(log_tip)

