Write an R script that contains statements to address the following numbered ite
ID: 3668697 • Letter: W
Question
Write an R script that contains statements to address the following numbered items. Use R comments (a line starting with the # symbol) to clearly indicate for which item the statements are intended. A template file titled “COS-206_Written_Assignment_Template.R” can be found in the Course Documents folder.
The file COS-206-data.csv (Course Documents) is a text file that contains comma-separated values (CSV).
Write R code(s) to read the contents of COS-206-data.csv and store them in a data frame called data.
Continuing with question 1 above, using the dataframe called data that you created,
create a new column called Range that is the difference between High and Low columns.
Delete the original High and Low columns.
The first 6 rows of data should now looks like below.
Date
Open
Close
Volume
Adj. Close
Range
1
2014-12-11
19.43
19.35
30400
19.35
0.51
2
2014-12-10
19.97
19.30
49300
19.30
0.83
3
2014-12-09
19.11
19.98
56400
19.98
1.03
4
2014-12-08
19.55
19.26
23700
19.26
0.41
5
2014-12-05
19.38
19.55
25200
19.55
0.21
6
2014-12-04
19.54
19.43
28400
19.43
0.32
Now sort data by the Range column. The first 6 rows should look like below.
Date
Open
Close
Volume
Adj. Close
Range
12
2014-11-25
19.59
19.60
45000
19.60
0.10
14
2014-11-21
19.73
19.62
44500
19.62
0.17
5
2014-12-05
19.38
19.55
25000
19.55
0.21
11
2014-11-26
19.64
19.52
17800
19.52
0.21
17
2014-11-18
19.64
19.53
54300
19.53
0.28
9
2014-12-01
19.25
19.37
64700
19.37
0.32
Using the reshape2 library and choosing “Date” as id.vars, convert the dataframe generated in question 3 to long form. The first 6 rows should look like below.
Date
Variable
Value
1
2014-11-25
Open
19.59
2
2014-11-21
Open
19.73
3
2014-12-05
Open
19.38
4
2014-11-26
Open
19.64
5
2014-11-18
Open
19.64
6
2014-12-01
Open
19.25
Date
Open
Close
Volume
Adj. Close
Range
1
2014-12-11
19.43
19.35
30400
19.35
0.51
2
2014-12-10
19.97
19.30
49300
19.30
0.83
3
2014-12-09
19.11
19.98
56400
19.98
1.03
4
2014-12-08
19.55
19.26
23700
19.26
0.41
5
2014-12-05
19.38
19.55
25200
19.55
0.21
6
2014-12-04
19.54
19.43
28400
19.43
0.32
Explanation / Answer
COS-206-dataRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.