Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Christina Exercises #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Christina Exercises
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#R Exercises

# Exercise 1: Print the Time
currenttime <- Sys.time()
print(currenttime)

# Exercise 2: Make a Simple Stopwatch
starttime <- Sys.time()
print(currenttime)

greeting <- "hello world"
print(greeting)

endtime <- Sys.time()
print(endtime - starttime)

# Exercise 3: Print a Word Provided by the User
# get input from user
my.word <- readline(prompt="Enter your word: ")
print(paste("Your word is ", my.word))


# Exercise 4: Validate User Input
my.word <- readline(prompt="Enter your word: ")
if(class(my.word)!= "character") {
my.word <- readline(prompt="This is not a word. Enter another: ")
print(paste("Your word is ", my.word))
} else {
print("This is a word")
}



# Exercise 5: Record and Print a List
GetMultipleNumbers <- function()
{
i <- 0
mylist = vector()
while(i<5) {
num <- readline(prompt="Input one integer: ")
mylist = c(mylist,num)
i <- i+1
}
# Loop over list and print
for (i in mylist) {
print(i)
}
}

GetMultipleNumbers()