Skip to content

Commit

Permalink
Update exercise for students
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwross committed Jan 11, 2017
1 parent 8abace8 commit 7f9c5f2
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions exercise-3/exercise.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
# Exercise-3: Calling built-in functions

# Create a variable `my.name` that contains your name
my.name <- "Joel Ross"


# Create a variable `name.length` that holds how many letters are in your name (use the `nchar()` function)
name.length <- nchar(my.name)


# Print the number of letters in your name
print(name.length)


# Create a variable `now.doing` that is your named followed by "is programming!" to the end of your name
# (use the `paste()` function)
now.doing <- paste(my.name, "is programming!")


# Make the `now.doing` variable upper case
toupper(now.doing)


### Bonus

# Pick two of your favorite numbers (between 1 and 100) and assign them to `fav.1` and `fav.2`
fav.1 <- 12
fav.2 <- 87


# Divide each number by the square root of 201 and save it as the same variable
fav.1 <- fav.1/sqrt(201)
fav.2 <- fav.2/sqrt(201)


# Create a variable `raw.sum` that is the sum of those two variables. Use the `sum()` function for practice
raw.sum <-sum(fav.1, fav.2)


# Create a variable `round.sum` that is the `raw.sum` rounded to 1 decimal place. Use the `round()` function
round.sum <- round(raw.sum, 1)


# Create two new variables `round.1` and `round.2` that are your `fav.1` and `fav.2` variables rounded
# to 1 decimal place
round.1 <- round(fav.1, 2)
round.2 <- round(fav.2, 2)


# Create a variable `sum.round` that is the sum of the rounded values
sum.round <- sum(round.1, round.2)


# Which is bigger, `round.sum` or `sum.round`? (You can use the `max()` function!)
max(sum.round, round.sum)

0 comments on commit 7f9c5f2

Please sign in to comment.