forked from INFO-201/m6-functions
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |