This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

# In this hw1.R assignment, we want students to:
#   - learn how to write a trivial R script
#   - learn how to run an R script via the source() function
#   - learn to answer our "write code ..." questions with R code that
#     isn't too specific (I'll describe this point more in class)
# We're hoping that this small exericse will lead to less trouble on
# hw2.R, which requires a more meaningful R script.
#
# You should replace all occurrences of "..." with your code. If you'd
# like to replace a single "..." with more than one line of code
# before my line (using your own variables), you may certainly do
# that.
#
# Name: Kayley Seow
# Email: kseow@wisc.edu

# We'll grade your homework by running this ".R" file via
#   source("hw1.R")

rm(list = ls()) # Remove all objects defined in workspace.

x = c(5, 7)

# Find the sum of the elements of the vector x.

# ... your code here, if you wish ...

answer.1 = sum(x)# ... set this variable correctly (please don't use "5+7"
# or "12": use more general code that will work even if x
# were changed)

cat(sep="", "sum of elements of x is ", answer.1, "\n")

# Write code to generate two random numbers from N(0, 1) and report
# their sum.

# ... your code here, if you wish ...

# we need to use the rnorm function in order to get the random number
rand = rnorm(n = 2,mean = 0,sd = 1)

answer.2 = sum(rand) # ... set this variable correctly

cat(sep="", "sum of two random N(0, 1) numbers is ", answer.2, "\n")
LS0tDQp0aXRsZTogIlNUQVQgMzAzIEhvbWV3b3JrIDEiDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQpUaGlzIGlzIGFuIFtSIE1hcmtkb3duXShodHRwOi8vcm1hcmtkb3duLnJzdHVkaW8uY29tKSBOb3RlYm9vay4gV2hlbiB5b3UgZXhlY3V0ZSBjb2RlIHdpdGhpbiB0aGUgbm90ZWJvb2ssIHRoZSByZXN1bHRzIGFwcGVhciBiZW5lYXRoIHRoZSBjb2RlLiANCg0KVHJ5IGV4ZWN1dGluZyB0aGlzIGNodW5rIGJ5IGNsaWNraW5nIHRoZSAqUnVuKiBidXR0b24gd2l0aGluIHRoZSBjaHVuayBvciBieSBwbGFjaW5nIH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