GEOG264_A3_Instructions
.pdf
keyboard_arrow_up
School
Cégep Vanier College *
*We aren’t endorsed by this school
Course
264
Subject
Geography
Date
Apr 3, 2024
Type
Pages
3
Uploaded by JusticeCapybaraMaster2866
GEOG 264 Programming for Environmental Sciences (Fall 2023)
Concordia University
1
Assignment #3
Instructor:
Hongyu Zhang
Teaching Assistant:
Cerine Madi
Assigned:
Monday, Oct. 23, 2023 at 12 pm Due:
Tuesday, October 31, 2023 at 12 pm Total:
30 marks (7% of your final grade)
Part A (24 marks)
1)
Read in the data-frame “
Extended
” from the Assignment 2 dataset CalgaryTemperature.csv
using the read.csv
function
.
Examine your data. The first column is the year, the second column contains January data, the third column contains February data, etc. 2)
(5 marks) Now you have your data read into R, so now you can start doing things with it. Extend the new matrix "
Extended
" so that it has 137 rows by 18 columns using cbind()
. The first 13 columns and 136 rows of Extended
should be set to be the same as the data from CalgaryTemperature.csv
. The values for the 5 columns 14-18 and first 136 rows you will have to calculate and add into Extended
. Column 14 of Extended
should contain the average Q1 temperature (Jan. to Mar.), column 15 should contain the average Q2 temperature (Apr. to June), column 16 average Q3 temperature (July to Sept.), column 17 average Q4 temperature (Oct. to Dec.), column 18 average annual temperature (Jan.-Dec.). 3)
(10 marks) Make a single nice attractive plot of all the 4 seasonal and annual temperatures over the 136 years and include it in the text file that you hand in. In other words, the years 1885-2020 will be your x-axis. Label your x and y axis, include a title, and a legend. Make sure the legend does not cover the data. Use color and line types to make an attractive plot. Describe the plot. What trend do you see? Are there any obvious changes? Include your answer in what you hand in. Include the code used to make the graph in your R script file.
4)
(4 marks) Continue working with the Extended data-frame. Now you want to compute the monthly, quarters, and annual mean temperatures. Add all the monthly, quarters, and annual means into Extended
as the last row using rbind()
.
5)
(4 marks) Make a nice attractive plot of the mean monthly temperatures (hand it in). This is different from 8). In other words, the months 1-12 will be your x-axis. Label your x and y axis, include a title, and a legend. Use color and line types to make an attractive plot. Describe the plot. What trend do you see? Include your answer in what you hand in. Include the code used to make the graph in your R script file.
GEOG 264 Programming for Environmental Sciences (Fall 2023)
Concordia University
2
6)
(1 mark) You also have to learn getting data back out of R once you are done doing your calculations. Use
write.csv(Extended, "ExtendedCalgary.csv")
or write.csv(data-
frame_name, "filename.csv")
to export a copy of Extended
back out of R as a .csv spreadsheet into your working directory. Leave R Studio and go back to your working directory, find ExtendedCalgary.csv
and open it and check that it is correct. Always check that your output files are correct! You can’t be too paranoid when programming!
Part B (6+5 marks)
1)
Read in R the “
oregonstations.csv
” dataset from Lab 2.
2)
(3 marks) Find the Westernmost Oregon weather station in this dataset. Longitude increases from West to East, so the Westernmost weather station has the lowest longitude. 3)
(3 marks) Find the Northernmost Oregon weather station in this dataset. Latitude increases from South to North, so the Northernmost weather station has the highest latitude. ●
Use a for loop with an if statement. ●
You cannot use the min() or max() R functions ●
You can use the absolute value function abs().
4)
(Bonus question: 5 marks) Find the two most distant weather stations in this dataset. The distance is the root of sum of the squares of the difference in latitude and longitude:
distance
=
√(
𝛥𝑙𝑎𝑡
)
2
+
(
𝛥𝑙??
)
2
●
Use a for loop with another for loop and an if statement nested within.
●
You can also alternatively use a while loop with an if statement nested within.
●
You cannot use the min() or max() R functions Get this program up and running correctly. Print the two most distant station numbers and the maximum distance in the console.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help