Question
CODE in R Train.r: # Delete everything out of the environment rm(list=ls()) # Does the script use require, library, or :: package? # rl if
CODE in R
Train.r:
# Delete everything out of the environment
rm(list=ls())
# Does the script use require, library, or :: package?
#
rl
if (any(grepl("library", rl)) |
any(grepl("require", rl)) |
any(grepl("::", rl, fixed = TRUE))) {
stop("This script may use a non-base package and therefore will receive a score of 0.")
}
# Even if you can get around this issue (by, say, adding the package to your
# .Rprofile file), the script will not work on our computer and therefore you
# will not receive points.
#
# Load functions
source("script.R")
# Points
points
earned = 10,
possible = 10)
# Check for the functions
fxns
"add_even",
"calculate_summary_statistics",
"is_magicsquare")
pts
for (i in seq_len(length(fxns))) {
pts
}
points
data.frame(check = "function names",
earned = pts,
possible = length(fxns)))
#############################################################################
# Check celsius_to_fahrenheit results
#############################################################################
celsius
fahrenheit
points
data.frame(check = "celsius_to_fahrenheit",
earned = sum(celsius_to_fahrenheit(celsius) == fahrenheit),
possible = length(fahrenheit)))
#############################################################################
# Check add_even results
#############################################################################
n
r
stopifnot(length(n) == length(r))
pts
for (i in seq_len(length(n))) {
pts
}
points
data.frame(check = "add_even",
earned = pts,
possible = length(n)))
#############################################################################
# Check is_magicsquare
#############################################################################
squares
matrix(c(2, 7, 6,
9, 5, 1,
4, 3, 8),
byrow = TRUE,
nrow = 3, ncol = 3),
matrix(c(1, 14, 14, 4,
11, 7, 6, 9,
8, 11, 10, 5,
13, 2, 3, 15),
byrow = TRUE,
nrow = 4, ncol = 4),
matrix(c(46, 8, 16, 20, 29, 7, 49,
3, 40, 35, 36, 18, 41, 2,
44, 12, 33, 23, 19, 38, 6,
28, 26, 11, 25, 39, 24, 22,
5, 37, 31, 27, 17, 13, 45,
48, 9, 15, 14, 32, 10, 47,
1, 43, 34, 30, 21, 42, 4),
byrow = TRUE,
nrow = 7, ncol = 7)
)
ms
pts
for (i in 1:length(squares)) {
pts
}
points
data.frame(check = "is_magicsquare",
earned = pts,
possible = length(ms)))
#############################################################################
# Check calculate_summary_statistics() results
#############################################################################
my_near
abs(a-b)
}
# ToothGrowth
s
pts
my_near(s$n, 60),
my_near(s$m, 18.81333),
my_near(s$s, 7.649315),
my_near(s$lcl, 16.83731),
my_near(s$ucl, 20.78936)
)
points
points,
data.frame(
check = "calculate_summary_statistics_ToothGrowth",
earned = pts,
possible = 5)
)
# missing values
vector_with_NAs
s
pts
my_near(s$n, 10),
my_near(s$m, 5.5),
my_near(s$s, 3.02765),
my_near(s$lcl, 3.334149),
my_near(s$ucl, 7.665851)
)
points
points,
data.frame(
check = "calculate_summary_statistics_with_NAs",
earned = pts,
possible = 5)
)
# different significance level
s
pts
my_near(s$lcl, 3.744928),
my_near(s$ucl, 7.255072)
)
points
points,
data.frame(
check = "calculate_summary_statistics_diff_error",
earned = pts,
possible = 2)
)
This assignment will focus on using R as a programming language. The intent of the assignment is to use control flow (e.g. if, else, while, for) as well as functions. You will only be allowed to use base R functions, i.e. functions in the stats, graphics, grDevices, utils, datasets, methods, and base packages. The assignment will be automatically graded, but not using Canvas. You will be required to provide an R script which will be read in using the source() command. This script should be named script.R and contain only functions. Then two scripts will be run to evaluate your functions: train.R and test.R. You will have access to the train.R file so you can see whether you pass the tests or not. Then we will run test.R to see if you pass the hidden tests. Check that the earned column is equal to the possible column. If either source commands produces an error or if the earned column is not equal to the possible column, then you have a bug in your code. (Of course, you may also have a bug in your code that the "train.R" file did not catch.) 3. Construct a function named is_magicsquare() that has an argument m that is a matrix. The function should return TRUE if the matrix is a magic square. A magic square is a square matrix where every row, every column, and both diagonals sum to the same number
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started