Lab 02 Problem 1: My median


Rate this product

Lab 02
For this homework, provide a rendered R Markdown file in pdf format
(you may render the R Markdown file to html, and then convert the html
file to pdf using the print function on a web browser). Indicate your student
number on the markdown file, and make a section for each problem.
Problem 1: My median
a) Write an R function called my.median. This function should take
a single parameter (a vector) and return the median of that vector.
Write this function without using the built-in R command median.
Provide the code for this function.
(4 points)
b) Consider the stock prices in the file AS-N100.tsv provided in the
archive for week 3. These data involve stock prices for 27 symbols
(in the column ticker ). Compute your student number modulo 27 and
add one, call this value a (i.e., a is a number between 1 and 27 inclusive). Imagine a list of the 27 symbols in alphabetical order. You will
examine the a-th symbol in this list: You may find the symbol using the
R code sort(unique(data$ticker))[a]. Compute the median
opening price of the symbol you examine over all rows in AS-N100.tsv
involving that symbol, using your my.median function. Provide all
code and output.
(2 points)
Problem 2: X marks the spot
a) The image Figure03.png (provided in the archive containing this lab) is
a satellite photo of Vancouver and the surrounding area. In this problem, you will mark the location of a library on this image automatically
1 of 2
STAT240 Spring 2023 SFU Due January 27th 5 5PM PST
using code. The upper left hand corner of this image has approximate GPS coordinates 49.410705,-124.217671. The lower right hand
corner of this image has approximate GPS coordinates 47.929083,-
121.994887. Consider the file libraries.json provided in the archive for
week 3. This file contains information about 21 branches of the Vancouver public library. Write R code to display Figure03.png, and to
mark an ‘X’ symbol on the GPS coordinates of the b-th library branch,
and to print the name and address of the library branch directly below the ‘X’. Here, b is your student number modulo 21 plus one (i.e.,
b is a number between 1 and 21 inclusive). Note that after loading the library rjson and loading libraries.json using libraries =
fromJSON(file = “libraries.json”), the coordinates of the
b-th branch can be accessed with: libraries [[“features”]]
[[b]] [[“geometry”]] $coordinates. And the branch name
and address can be accessed with: libraries [[“features”]]
[[b]] [[“properties”]] $maptip. Provide your code, and the
resulting display.
(4 points)
2 of 2


There are no reviews yet.

Be the first to review “Lab 02 Problem 1: My median”

Your email address will not be published. Required fields are marked *

Scroll to Top