Due date : 25 Dec 2020, 23:59


Objectives

Hints : You can use these functions and the main web page of our course - LINK

getwd()
setwd()
list.files()
file.path()

read.csv()
read.delim()
read.table()

class()
str()
length()
sim()
attributes()
attr()
typeof()

mean()
sum()
colMeans()
rowMeans()

na.omit()

plot()
View()

Instructions

PART-1 Download, Get or Find and Read Data

R-STUDIO AND DATA

  1. Go to the webpage of the course
  2. Open Data “Istanbul_Goztepe_Mean_Temperature_1839-2013_Monthly” (.dat) by click the LINK
  3. Copy and Paste it in your “Downloads” directory in a text file with “.dat” extension
  4. Open your R-Studio, Create an R-Project, Create an R-Script (you will write and save your all codes from now in this script), and try to read the data file with each of these ways:

WAY 1 - GO TO FILE

  1. Check your Project Name and your Working directory
  2. Go to “Downloads” directory in R-Studio, using console
  3. List files and Read Data with three different read functions ( read.csv(), read.delim(), read.table())
  4. Choose the best for you ( or change the options if it is necessary, regarding header or separators )
  5. Assign your data as “temp_1”

WAY 2 - CALL THE FILE

  1. Go Back to your Working directory
  2. Define your data file path with file.path() ( remember, you downloaded the data in your Downloads folder )
  3. Assign the path a new variable as “path_my_file”
  4. Use your best read…() function to read the file with “path_my_file”
  5. Assign your data as “temp_2”

WAY 3 - IMPORT THE FILE

  1. Use “Import Datase”
  2. Chose “From Text (base)” option
  3. Try to assign your data as “temp_3” at this time

WAY 4 - GET THE FILE (WITH URL)

  1. Copy the LINK of data
  2. Use your best read() function
  3. Read the file with this function and LINK
  4. Assign your data as “temp_4”

LAST STEP

  1. Choose your favorite data ( temp_1, temp_2, temp_3 or temp_4 ) and assign as just “temp

PART-2 Play with the Data

MEET WITH THE DATA

  1. Look at class and structure
  2. Learn attributes and dimensions
  3. Rename attributes ( ex: Months for each column and years for each raw ) ( attributes() and month.name or month.abb )
  • By the way, your data have to include just temperature values when you print it. Years and months have to be just attributes of data.

CLEAR NA AND CHOOSE COLUMN

  1. Print “temp”. Do you see irrelevant numbers ? If so, change them as NA
  • Now your “temp” data must seem like this

  1. Delete rows which include NA ( which() or na.omit() )
  • Now your “temp” data must seem like this

  1. Assign it as new “temp” again
  2. Select summer season
  3. Assign it as “temp_summer” ( three months)

USE LOGICAL OPERATORS

  1. Compare June and July: Find and print the years when June temperatures were less than July. ( which() )
  2. Calculate mean temperature for each months (you will probably need the na.rm (NA Remove) option ) and assign it as “avg_month”
  1. Print minimum and maximum values for “avg_month”
  2. Find which year and which month minimum and maximum values were observed12. Calculate the mean temperature for each years (you will probably need the na.rm (NA Remove) option ) “avg_year”
  1. Calculate the mean temperature of all data and assign it as “avg_temp” and print it
  2. Print the years of “avg_year” which are greater than or equal to “avg_temp”

PLOT

  1. Plot temperature for June ( for each year ), add title and unit
  2. Edit y-axis and x-axis label ( to see which years are they )
  3. What about July and August ? Plot them on the same figure with June.
  4. Is there any strangeness thing, what do you think ? Compare three plots
  5. Plot “avg_month”, make the type of line as “line” and colorful. What is reason of the inverted V letter shape
  6. Plot “avg_year”, make the line dashed line. What do you think
  7. Plot just temperature for just 1990 ( my birth year )

THE LAST BUT NOT LEAST

  1. Run these codes. Can you explain what am I doing with my codes which were given below? What are these x-axis and y-axis in here? ( which years or months are they? ) What is the result of this figure, what do you see and what do you think? what do colors mean? Can you edit title and x-axis and y-axis labels?
plot(seq(1,12),  temp[142,1:12] , type = "l", col = "red")
lines(seq(1,12), temp[1,1:12]   , type = "l", col = "blue")
legend("topleft",c("blue","red"),fill=c("blue","red"))
abline(h = mean(colMeans(temp, na.rm = T)))

par(mfrow = c(2, 2))    #or try par(mfrow = c(4, 1))
plot(ylim = c(0,30), rowMeans(temp[,9:11])      , type="l", col="orange")
plot(ylim = c(0,30), rowMeans(temp[,c(12,1,2)]) , type="l", col="blue")
plot(ylim = c(0,30), rowMeans(temp[,3:5])       , type="l", col="green")
plot(ylim = c(0,30), rowMeans(temp[,6:8])       , type="l", col="red")


For questions or problems, please use Ninova

Emir