Software Tools for Earth and Environmental Science

–7th WEEK–

Emir Toker

04/12/2020

R Language - Part 3

  • Syllabus, Last Week and Book

  • R Language - Part 3

    • Read
    • Write
    • Plot
  • TakeHome - MidTerm Project

  • Additional Course - II

  • Next Week - R Programming

Syllabus, Last Week and Book

Syllabus

Extended Syllabus PDF

Last Week

LINK

Book

PDF - (Pg. 127-133 and 150-155)

Homework - I and II

*due date: 07/12/2020 23:59

Homework - I

Create a Notebook

Homework - II

Practice - Data Types and Structures

Additional Course - II

Today, 15:00 - 16:00

R Language

R Language - Part 1 & Part 2

  • Basic Math, Assigment, Comment
  • Data Types - Classes
    • Numeric
    • Integer
    • Logical
    • Character
    • Special Values
  • Data Structures - Objects
    • Vector
    • Matrice
    • Array
    • Data Frame
    • List

LINK

R Language - Part 3

  • Read

  • Write

  • Plot

LINK

Practice - R Language

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “18397_Cekmekoy_Omerli_15dk.txt”
mydata <- read.csv(file = "Cekmekoy_Omerli_15min.txt", 
                   header = TRUE, 
                   sep = ";")
mydata
##     sta_no year month day hour minutes temp precipitation pressure
## 1    18397 2017     7  26   18       0 23.9          0.00   1003.0
## 2    18397 2017     7  26   18      15 23.9          0.00   1003.1
## 3    18397 2017     7  26   18      30 23.8          0.00   1003.2
## 4    18397 2017     7  26   18      45 23.8          0.00   1003.2
## 5    18397 2017     7  26   19       0 23.6          0.00   1003.2
## 6    18397 2017     7  26   19      15 23.2          0.00   1003.1
## 7    18397 2017     7  26   19      30 23.2          0.00   1003.1
## 8    18397 2017     7  26   19      45 23.1          0.00   1003.1
## 9    18397 2017     7  26   20       0 23.0          0.00   1003.1
## 10   18397 2017     7  26   20      15 22.8          0.00   1003.0
## 11   18397 2017     7  26   20      30 22.5          0.00   1003.0
## 12   18397 2017     7  26   20      45 22.4          0.00   1003.0
## 13   18397 2017     7  26   21       0 22.2          0.00   1003.0
## 14   18397 2017     7  26   21      15 22.3          0.00   1003.0
## 15   18397 2017     7  26   21      30 22.2          0.00   1003.1
## 16   18397 2017     7  26   21      45 21.7          0.00   1003.1
## 17   18397 2017     7  26   22       0 21.9          0.00   1003.2
## 18   18397 2017     7  26   22      15 21.7          0.00   1003.3
## 19   18397 2017     7  26   22      30 21.6          0.00   1003.3
## 20   18397 2017     7  26   22      45 22.2          0.00   1003.4
## 21   18397 2017     7  26   23       0 22.2          0.00   1003.4
## 22   18397 2017     7  26   23      15 22.1          0.00   1003.5
## 23   18397 2017     7  26   23      30 22.3          0.00   1003.4
## 24   18397 2017     7  26   23      45 22.5          0.00   1003.4
## 25   18397 2017     7  27    0       0 22.3          0.00   1003.4
## 26   18397 2017     7  27    0      15 22.2          0.00   1003.2
## 27   18397 2017     7  27    0      30 22.5          0.00   1003.2
## 28   18397 2017     7  27    0      45 22.6          0.00   1003.2
## 29   18397 2017     7  27    1       0 22.6          0.00   1003.3
## 30   18397 2017     7  27    1      15 22.6          0.00   1003.4
## 31   18397 2017     7  27    1      30 22.6          0.00   1003.2
## 32   18397 2017     7  27    1      45 22.7          0.00   1003.2
## 33   18397 2017     7  27    2       0 22.6          0.00   1003.3
## 34   18397 2017     7  27    2      15 22.5          0.00   1003.2
## 35   18397 2017     7  27    2      30 22.6          0.00   1003.2
## 36   18397 2017     7  27    2      45 22.5          0.00   1003.1
## 37   18397 2017     7  27    3       0 22.5          0.00   1003.1
## 38   18397 2017     7  27    3      15 22.4          0.00   1003.0
## 39   18397 2017     7  27    3      30 22.5          0.00   1003.1
## 40   18397 2017     7  27    3      45 22.4          0.00   1003.3
## 41   18397 2017     7  27    4       0 22.5          0.00   1003.4
## 42   18397 2017     7  27    4      15 22.6          0.00   1003.5
## 43   18397 2017     7  27    4      30 23.0          0.00   1003.5
## 44   18397 2017     7  27    4      45 23.2          0.00   1003.5
## 45   18397 2017     7  27    5       0 24.2          0.00   1003.6
## 46   18397 2017     7  27    5      15 25.1          0.00   1003.5
## 47   18397 2017     7  27    5      30 25.5          0.00   1003.4
## 48   18397 2017     7  27    5      45 26.1          0.00   1003.3
## 49   18397 2017     7  27    6       0 27.1          0.00   1003.3
## 50   18397 2017     7  27    6      15 26.9          0.00   1003.3
## 51   18397 2017     7  27    6      30 27.6          0.00   1003.3
## 52   18397 2017     7  27    6      45 28.0          0.00   1003.2
## 53   18397 2017     7  27    7       0 28.4          0.00   1003.1
## 54   18397 2017     7  27    7      15 28.5          0.00   1003.1
## 55   18397 2017     7  27    7      30 29.3          0.00   1003.0
## 56   18397 2017     7  27    7      45 30.2          0.00   1002.9
## 57   18397 2017     7  27    8       0 30.1          0.00   1002.8
## 58   18397 2017     7  27    8      15 30.1          0.00   1002.8
## 59   18397 2017     7  27    8      30 30.4          0.00   1002.8
## 60   18397 2017     7  27    8      45 30.4          0.00   1002.8
## 61   18397 2017     7  27    9       0 30.8          0.00   1002.9
## 62   18397 2017     7  27    9      15 30.9          0.00   1002.8
## 63   18397 2017     7  27    9      30 31.0          0.00   1002.6
## 64   18397 2017     7  27    9      45 31.5          0.00   1002.6
## 65   18397 2017     7  27   10       0 31.2          0.00   1002.6
## 66   18397 2017     7  27   10      15 30.9          0.00   1002.4
## 67   18397 2017     7  27   10      30 30.9          0.00   1002.4
## 68   18397 2017     7  27   10      45 30.4          0.00   1002.3
## 69   18397 2017     7  27   11       0 30.4          0.00   1002.1
## 70   18397 2017     7  27   11      15 30.0          0.00   1001.9
## 71   18397 2017     7  27   11      30 29.2          0.00   1001.9
## 72   18397 2017     7  27   11      45 29.5          0.00   1001.7
## 73   18397 2017     7  27   12       0 29.4          0.00   1001.6
## 74   18397 2017     7  27   12      15 29.3          0.00   1001.3
## 75   18397 2017     7  27   12      30 29.6          0.00   1001.2
## 76   18397 2017     7  27   12      45 28.8          0.00   1001.3
## 77   18397 2017     7  27   13       0 29.0          0.00   1001.1
## 78   18397 2017     7  27   13      15 29.0          0.00   1001.2
## 79   18397 2017     7  27   13      30 29.2          0.00   1001.3
## 80   18397 2017     7  27   13      45 28.4          0.00   1001.5
## 81   18397 2017     7  27   14       0 27.8          0.00   1001.6
## 82   18397 2017     7  27   14      15 27.4          0.00   1001.6
## 83   18397 2017     7  27   14      30 26.6          0.00   1001.5
## 84   18397 2017     7  27   14      45 26.2          0.00   1001.2
## 85   18397 2017     7  27   15       0 25.8          0.00   1001.1
## 86   18397 2017     7  27   15      15 25.6          0.00   1001.0
## 87   18397 2017     7  27   15      30 25.4          0.00   1000.9
## 88   18397 2017     7  27   15      45 24.2          0.00   1001.8
## 89   18397 2017     7  27   16       0 19.2          7.01   1003.7
## 90   18397 2017     7  27   16      15 19.5          8.80   1003.2
## 91   18397 2017     7  27   16      30 20.1          0.25   1003.1
## 92   18397 2017     7  27   16      45 20.8          0.00   1003.7
## 93   18397 2017     7  27   17       0 21.2          1.13  -9999.0
## 94   18397 2017     7  27   17      15 21.4          0.02   1005.6
## 95   18397 2017     7  27   17      30 21.4          1.25   1005.4
## 96   18397 2017     7  27   17      45 21.4          2.75   1005.1
## 97   18397 2017     7  27   18       0 21.2          0.00   1005.1
## 98   18397 2017     7  27   18      15 21.0          0.00  -9999.0
## 99   18397 2017     7  27   18      30 20.8          0.00   1006.3
## 100  18397 2017     7  27   18      45 20.9          0.00  -9999.0
## 101  18397 2017     7  27   19       0 20.8          0.19   1005.7
## 102  18397 2017     7  27   19      15 20.7          0.00   1006.2
## 103  18397 2017     7  27   19      30 20.8          0.20   1003.6
## 104  18397 2017     7  27   19      45 20.8          0.22   1003.7
## 105  18397 2017     7  27   20       0 20.9          0.00  -9999.0
## 106  18397 2017     7  27   20      15 20.6          0.00  -9999.0
## 107  18397 2017     7  27   20      30 20.6          0.00   1005.1
## 108  18397 2017     7  27   20      45 20.5          0.00   1005.6
## 109  18397 2017     7  27   21       0 20.7          0.00   1005.5
## 110  18397 2017     7  27   21      15 20.8          0.00   1005.7
## 111  18397 2017     7  27   21      30 20.4          0.00   1005.6
## 112  18397 2017     7  27   21      45 20.4          0.00   1005.8
## 113  18397 2017     7  27   22       0 20.6          0.00   1005.8
## 114  18397 2017     7  27   22      15 20.5          0.00   1005.9
## 115  18397 2017     7  27   22      30 20.4          0.00   1006.0
## 116  18397 2017     7  27   22      45 20.5          0.00   1005.9
## 117  18397 2017     7  27   23       0 20.5          0.00   1005.9
## 118  18397 2017     7  27   23      15 20.6          0.00   1005.9
## 119  18397 2017     7  27   23      30 20.5          0.00   1006.0
## 120  18397 2017     7  27   23      45 20.5          0.00   1006.0
## 121  18397 2017     7  28    0       0 20.4          0.00   1006.0
##     relative_humidity
## 1                  94
## 2                  95
## 3                  96
## 4                  96
## 5                  96
## 6                  97
## 7                  97
## 8                  98
## 9                  98
## 10                 98
## 11                 98
## 12                 99
## 13                 99
## 14                 99
## 15                 99
## 16                 99
## 17                 99
## 18                 99
## 19                 99
## 20                100
## 21                100
## 22                100
## 23                100
## 24                100
## 25                100
## 26                100
## 27                100
## 28                100
## 29                100
## 30                100
## 31                100
## 32                100
## 33                100
## 34                100
## 35                100
## 36                100
## 37                100
## 38                100
## 39                100
## 40                100
## 41                100
## 42                100
## 43                100
## 44                100
## 45                100
## 46                 97
## 47                 84
## 48                 82
## 49                 79
## 50                 78
## 51                 78
## 52                 76
## 53                 76
## 54                 75
## 55                 73
## 56                 65
## 57                 57
## 58                 60
## 59                 53
## 60                 52
## 61                 51
## 62                 51
## 63                 50
## 64                 53
## 65                 52
## 66                 57
## 67                 58
## 68                 59
## 69                 60
## 70                 61
## 71                 65
## 72                 66
## 73                 67
## 74                 66
## 75                 68
## 76                 70
## 77                 68
## 78                 69
## 79                 69
## 80                 71
## 81                 72
## 82                 72
## 83                 77
## 84                 79
## 85                 80
## 86                 82
## 87                 84
## 88                 79
## 89                 99
## 90                100
## 91                100
## 92                100
## 93                100
## 94                100
## 95                100
## 96                100
## 97                100
## 98                100
## 99                100
## 100               100
## 101               100
## 102               100
## 103               100
## 104               100
## 105               100
## 106               100
## 107               100
## 108               100
## 109               100
## 110               100
## 111               100
## 112               100
## 113               100
## 114               100
## 115               100
## 116               100
## 117               100
## 118               100
## 119               100
## 120               100
## 121               100

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Check the class and structure of your new data.
## [1] "data.frame"
## 'data.frame':    121 obs. of  10 variables:
##  $ sta_no           : int  18397 18397 18397 18397 18397 18397 18397 18397 18397 18397 ...
##  $ year             : int  2017 2017 2017 2017 2017 2017 2017 2017 2017 2017 ...
##  $ month            : int  7 7 7 7 7 7 7 7 7 7 ...
##  $ day              : int  26 26 26 26 26 26 26 26 26 26 ...
##  $ hour             : int  18 18 18 18 19 19 19 19 20 20 ...
##  $ minutes          : int  0 15 30 45 0 15 30 45 0 15 ...
##  $ temp             : num  23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23 22.8 ...
##  $ precipitation    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ pressure         : num  1003 1003 1003 1003 1003 ...
##  $ relative_humidity: int  94 95 96 96 96 97 97 98 98 98 ...
## $names
##  [1] "sta_no"            "year"              "month"            
##  [4] "day"               "hour"              "minutes"          
##  [7] "temp"              "precipitation"     "pressure"         
## [10] "relative_humidity"
## 
## $class
## [1] "data.frame"
## 
## $row.names
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108
## [109] 109 110 111 112 113 114 115 116 117 118 119 120 121

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Take the “Temperature” parameter and assign it as a new variable.
temp_data <- mydata$temp
temp_data
##   [1] 23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23.0 22.8 22.5 22.4 22.2 22.3 22.2
##  [16] 21.7 21.9 21.7 21.6 22.2 22.2 22.1 22.3 22.5 22.3 22.2 22.5 22.6 22.6 22.6
##  [31] 22.6 22.7 22.6 22.5 22.6 22.5 22.5 22.4 22.5 22.4 22.5 22.6 23.0 23.2 24.2
##  [46] 25.1 25.5 26.1 27.1 26.9 27.6 28.0 28.4 28.5 29.3 30.2 30.1 30.1 30.4 30.4
##  [61] 30.8 30.9 31.0 31.5 31.2 30.9 30.9 30.4 30.4 30.0 29.2 29.5 29.4 29.3 29.6
##  [76] 28.8 29.0 29.0 29.2 28.4 27.8 27.4 26.6 26.2 25.8 25.6 25.4 24.2 19.2 19.5
##  [91] 20.1 20.8 21.2 21.4 21.4 21.4 21.2 21.0 20.8 20.9 20.8 20.7 20.8 20.8 20.9
## [106] 20.6 20.6 20.5 20.7 20.8 20.4 20.4 20.6 20.5 20.4 20.5 20.5 20.6 20.5 20.5
## [121] 20.4

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Plot the “temperature” vector.
plot(temp_data)

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Print minimum temperature and find which element is the minimum in temperature vector.
print(min(temp_data))
## [1] 19.2
which(temp_data==19.2) # which(temp_data==min(temp_data))
## [1] 89

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. change the minimum value with NA and Print.
temp_data[89] <- NA

temp_data[which(temp_data==19.2)] <- NA

temp_data[which(temp_data==min(temp_data))] <- NA

print(temp_data)
##   [1] 23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23.0 22.8 22.5 22.4 22.2 22.3 22.2
##  [16] 21.7 21.9 21.7 21.6 22.2 22.2 22.1 22.3 22.5 22.3 22.2 22.5 22.6 22.6 22.6
##  [31] 22.6 22.7 22.6 22.5 22.6 22.5 22.5 22.4 22.5 22.4 22.5 22.6 23.0 23.2 24.2
##  [46] 25.1 25.5 26.1 27.1 26.9 27.6 28.0 28.4 28.5 29.3 30.2 30.1 30.1 30.4 30.4
##  [61] 30.8 30.9 31.0 31.5 31.2 30.9 30.9 30.4 30.4 30.0 29.2 29.5 29.4 29.3 29.6
##  [76] 28.8 29.0 29.0 29.2 28.4 27.8 27.4 26.6 26.2 25.8 25.6 25.4 24.2   NA 19.5
##  [91] 20.1 20.8 21.2 21.4 21.4 21.4 21.2 21.0 20.8 20.9 20.8 20.7 20.8 20.8 20.9
## [106] 20.6 20.6 20.5 20.7 20.8 20.4 20.4 20.6 20.5 20.4 20.5 20.5 20.6 20.5 20.5
## [121] 20.4

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Plot the new “temperature” vector.

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Replace these new temperature values with old temperature values located in your data frame.
mydata$temp <- temp_data

mydata
##     sta_no year month day hour minutes temp precipitation pressure
## 1    18397 2017     7  26   18       0 23.9          0.00   1003.0
## 2    18397 2017     7  26   18      15 23.9          0.00   1003.1
## 3    18397 2017     7  26   18      30 23.8          0.00   1003.2
## 4    18397 2017     7  26   18      45 23.8          0.00   1003.2
## 5    18397 2017     7  26   19       0 23.6          0.00   1003.2
## 6    18397 2017     7  26   19      15 23.2          0.00   1003.1
## 7    18397 2017     7  26   19      30 23.2          0.00   1003.1
## 8    18397 2017     7  26   19      45 23.1          0.00   1003.1
## 9    18397 2017     7  26   20       0 23.0          0.00   1003.1
## 10   18397 2017     7  26   20      15 22.8          0.00   1003.0
## 11   18397 2017     7  26   20      30 22.5          0.00   1003.0
## 12   18397 2017     7  26   20      45 22.4          0.00   1003.0
## 13   18397 2017     7  26   21       0 22.2          0.00   1003.0
## 14   18397 2017     7  26   21      15 22.3          0.00   1003.0
## 15   18397 2017     7  26   21      30 22.2          0.00   1003.1
## 16   18397 2017     7  26   21      45 21.7          0.00   1003.1
## 17   18397 2017     7  26   22       0 21.9          0.00   1003.2
## 18   18397 2017     7  26   22      15 21.7          0.00   1003.3
## 19   18397 2017     7  26   22      30 21.6          0.00   1003.3
## 20   18397 2017     7  26   22      45 22.2          0.00   1003.4
## 21   18397 2017     7  26   23       0 22.2          0.00   1003.4
## 22   18397 2017     7  26   23      15 22.1          0.00   1003.5
## 23   18397 2017     7  26   23      30 22.3          0.00   1003.4
## 24   18397 2017     7  26   23      45 22.5          0.00   1003.4
## 25   18397 2017     7  27    0       0 22.3          0.00   1003.4
## 26   18397 2017     7  27    0      15 22.2          0.00   1003.2
## 27   18397 2017     7  27    0      30 22.5          0.00   1003.2
## 28   18397 2017     7  27    0      45 22.6          0.00   1003.2
## 29   18397 2017     7  27    1       0 22.6          0.00   1003.3
## 30   18397 2017     7  27    1      15 22.6          0.00   1003.4
## 31   18397 2017     7  27    1      30 22.6          0.00   1003.2
## 32   18397 2017     7  27    1      45 22.7          0.00   1003.2
## 33   18397 2017     7  27    2       0 22.6          0.00   1003.3
## 34   18397 2017     7  27    2      15 22.5          0.00   1003.2
## 35   18397 2017     7  27    2      30 22.6          0.00   1003.2
## 36   18397 2017     7  27    2      45 22.5          0.00   1003.1
## 37   18397 2017     7  27    3       0 22.5          0.00   1003.1
## 38   18397 2017     7  27    3      15 22.4          0.00   1003.0
## 39   18397 2017     7  27    3      30 22.5          0.00   1003.1
## 40   18397 2017     7  27    3      45 22.4          0.00   1003.3
## 41   18397 2017     7  27    4       0 22.5          0.00   1003.4
## 42   18397 2017     7  27    4      15 22.6          0.00   1003.5
## 43   18397 2017     7  27    4      30 23.0          0.00   1003.5
## 44   18397 2017     7  27    4      45 23.2          0.00   1003.5
## 45   18397 2017     7  27    5       0 24.2          0.00   1003.6
## 46   18397 2017     7  27    5      15 25.1          0.00   1003.5
## 47   18397 2017     7  27    5      30 25.5          0.00   1003.4
## 48   18397 2017     7  27    5      45 26.1          0.00   1003.3
## 49   18397 2017     7  27    6       0 27.1          0.00   1003.3
## 50   18397 2017     7  27    6      15 26.9          0.00   1003.3
## 51   18397 2017     7  27    6      30 27.6          0.00   1003.3
## 52   18397 2017     7  27    6      45 28.0          0.00   1003.2
## 53   18397 2017     7  27    7       0 28.4          0.00   1003.1
## 54   18397 2017     7  27    7      15 28.5          0.00   1003.1
## 55   18397 2017     7  27    7      30 29.3          0.00   1003.0
## 56   18397 2017     7  27    7      45 30.2          0.00   1002.9
## 57   18397 2017     7  27    8       0 30.1          0.00   1002.8
## 58   18397 2017     7  27    8      15 30.1          0.00   1002.8
## 59   18397 2017     7  27    8      30 30.4          0.00   1002.8
## 60   18397 2017     7  27    8      45 30.4          0.00   1002.8
## 61   18397 2017     7  27    9       0 30.8          0.00   1002.9
## 62   18397 2017     7  27    9      15 30.9          0.00   1002.8
## 63   18397 2017     7  27    9      30 31.0          0.00   1002.6
## 64   18397 2017     7  27    9      45 31.5          0.00   1002.6
## 65   18397 2017     7  27   10       0 31.2          0.00   1002.6
## 66   18397 2017     7  27   10      15 30.9          0.00   1002.4
## 67   18397 2017     7  27   10      30 30.9          0.00   1002.4
## 68   18397 2017     7  27   10      45 30.4          0.00   1002.3
## 69   18397 2017     7  27   11       0 30.4          0.00   1002.1
## 70   18397 2017     7  27   11      15 30.0          0.00   1001.9
## 71   18397 2017     7  27   11      30 29.2          0.00   1001.9
## 72   18397 2017     7  27   11      45 29.5          0.00   1001.7
## 73   18397 2017     7  27   12       0 29.4          0.00   1001.6
## 74   18397 2017     7  27   12      15 29.3          0.00   1001.3
## 75   18397 2017     7  27   12      30 29.6          0.00   1001.2
## 76   18397 2017     7  27   12      45 28.8          0.00   1001.3
## 77   18397 2017     7  27   13       0 29.0          0.00   1001.1
## 78   18397 2017     7  27   13      15 29.0          0.00   1001.2
## 79   18397 2017     7  27   13      30 29.2          0.00   1001.3
## 80   18397 2017     7  27   13      45 28.4          0.00   1001.5
## 81   18397 2017     7  27   14       0 27.8          0.00   1001.6
## 82   18397 2017     7  27   14      15 27.4          0.00   1001.6
## 83   18397 2017     7  27   14      30 26.6          0.00   1001.5
## 84   18397 2017     7  27   14      45 26.2          0.00   1001.2
## 85   18397 2017     7  27   15       0 25.8          0.00   1001.1
## 86   18397 2017     7  27   15      15 25.6          0.00   1001.0
## 87   18397 2017     7  27   15      30 25.4          0.00   1000.9
## 88   18397 2017     7  27   15      45 24.2          0.00   1001.8
## 89   18397 2017     7  27   16       0   NA          7.01   1003.7
## 90   18397 2017     7  27   16      15 19.5          8.80   1003.2
## 91   18397 2017     7  27   16      30 20.1          0.25   1003.1
## 92   18397 2017     7  27   16      45 20.8          0.00   1003.7
## 93   18397 2017     7  27   17       0 21.2          1.13  -9999.0
## 94   18397 2017     7  27   17      15 21.4          0.02   1005.6
## 95   18397 2017     7  27   17      30 21.4          1.25   1005.4
## 96   18397 2017     7  27   17      45 21.4          2.75   1005.1
## 97   18397 2017     7  27   18       0 21.2          0.00   1005.1
## 98   18397 2017     7  27   18      15 21.0          0.00  -9999.0
## 99   18397 2017     7  27   18      30 20.8          0.00   1006.3
## 100  18397 2017     7  27   18      45 20.9          0.00  -9999.0
## 101  18397 2017     7  27   19       0 20.8          0.19   1005.7
## 102  18397 2017     7  27   19      15 20.7          0.00   1006.2
## 103  18397 2017     7  27   19      30 20.8          0.20   1003.6
## 104  18397 2017     7  27   19      45 20.8          0.22   1003.7
## 105  18397 2017     7  27   20       0 20.9          0.00  -9999.0
## 106  18397 2017     7  27   20      15 20.6          0.00  -9999.0
## 107  18397 2017     7  27   20      30 20.6          0.00   1005.1
## 108  18397 2017     7  27   20      45 20.5          0.00   1005.6
## 109  18397 2017     7  27   21       0 20.7          0.00   1005.5
## 110  18397 2017     7  27   21      15 20.8          0.00   1005.7
## 111  18397 2017     7  27   21      30 20.4          0.00   1005.6
## 112  18397 2017     7  27   21      45 20.4          0.00   1005.8
## 113  18397 2017     7  27   22       0 20.6          0.00   1005.8
## 114  18397 2017     7  27   22      15 20.5          0.00   1005.9
## 115  18397 2017     7  27   22      30 20.4          0.00   1006.0
## 116  18397 2017     7  27   22      45 20.5          0.00   1005.9
## 117  18397 2017     7  27   23       0 20.5          0.00   1005.9
## 118  18397 2017     7  27   23      15 20.6          0.00   1005.9
## 119  18397 2017     7  27   23      30 20.5          0.00   1006.0
## 120  18397 2017     7  27   23      45 20.5          0.00   1006.0
## 121  18397 2017     7  28    0       0 20.4          0.00   1006.0
##     relative_humidity
## 1                  94
## 2                  95
## 3                  96
## 4                  96
## 5                  96
## 6                  97
## 7                  97
## 8                  98
## 9                  98
## 10                 98
## 11                 98
## 12                 99
## 13                 99
## 14                 99
## 15                 99
## 16                 99
## 17                 99
## 18                 99
## 19                 99
## 20                100
## 21                100
## 22                100
## 23                100
## 24                100
## 25                100
## 26                100
## 27                100
## 28                100
## 29                100
## 30                100
## 31                100
## 32                100
## 33                100
## 34                100
## 35                100
## 36                100
## 37                100
## 38                100
## 39                100
## 40                100
## 41                100
## 42                100
## 43                100
## 44                100
## 45                100
## 46                 97
## 47                 84
## 48                 82
## 49                 79
## 50                 78
## 51                 78
## 52                 76
## 53                 76
## 54                 75
## 55                 73
## 56                 65
## 57                 57
## 58                 60
## 59                 53
## 60                 52
## 61                 51
## 62                 51
## 63                 50
## 64                 53
## 65                 52
## 66                 57
## 67                 58
## 68                 59
## 69                 60
## 70                 61
## 71                 65
## 72                 66
## 73                 67
## 74                 66
## 75                 68
## 76                 70
## 77                 68
## 78                 69
## 79                 69
## 80                 71
## 81                 72
## 82                 72
## 83                 77
## 84                 79
## 85                 80
## 86                 82
## 87                 84
## 88                 79
## 89                 99
## 90                100
## 91                100
## 92                100
## 93                100
## 94                100
## 95                100
## 96                100
## 97                100
## 98                100
## 99                100
## 100               100
## 101               100
## 102               100
## 103               100
## 104               100
## 105               100
## 106               100
## 107               100
## 108               100
## 109               100
## 110               100
## 111               100
## 112               100
## 113               100
## 114               100
## 115               100
## 116               100
## 117               100
## 118               100
## 119               100
## 120               100
## 121               100

Practice - R Language

  1. Read and assign your csv data (Header or seperator ?). “Cekmekoy_Omerli_15min.txt”
  2. Check the class and structure of your new data.
  3. Take the “Temperature” parameter and assign it as a new variable.
  4. Plot the “temperature” vector.
  5. Print minimum temperature and find which element is the minimum in temperature vector.
  6. change the minimum value with NA and Print.
  7. Plot the new “temperature” vector.
  8. Replace these new temperature values with old temperature values located in your data frame.
  9. Write your data frame as a new csv file.

Practice - R Language

  1. Write your data frame as a new csv file.
write.csv(mydata, file = "new_data.csv")

BONUS - Create a Function

What is Function ?

A function is a set of statements organized together to perform a specific task

ex: mean() (arithmetic mean)

x <- c(1,2,3)
mean(x)
## [1] 2
(1+2+3) / 3
## [1] 2

BONUS - Create a Function

What is Function ?

A function is a set of statements organized together to perform a specific task

ex: sample() (takes a sample of the specified size from the elements of x )

sample(c(1,6,32,7), size = 2)
## [1] 32  1

ex: sum() (returns the sum of all the values)

Practice

Create a Function

Problem: Take a sample belonged to population and sum

box <- 1:6                    # This is my population in a BOX
my_samp <- sample(box, size = 2) # This is my sample, I choose two var.
sum(my_samp)
box
samp

I want to create a new function named my_roll()

my_roll <- function(box) {
box <- 1:6 
my_samp <- sample(box) 
sum(my_samp)
}
my_roll()

Practice

Problem: I want to define population myself, in every time. remove pre-defined population box ?

my_roll2 <- function(box) {
my_samp <- sample(box, size = 2) 
sum(my_samp)
}
my_roll2(box)

box ?

box = 1:6
my_roll2(box)

my_roll2(box = 1:6)
my_roll2(1:6)

Practice

Create a Function

  • You can add new options
  • { } and () are important

Workshop - Midterm Project

Workshop - Midterm Project

  • Open a new R notebook
  • Go to course home page, (Midterm Project)
  • Click Rmd and Open “Midterm_Project.Rmd”
  • Copy all code and paste in your R notebook
  • Same way, open STATION DATA (18397_Cekmekoy_Omerli_15dk.txt) and paste file in your project directory.
  • Start to follow Instructions

Next Week (not next, the other one)

Next Week (not next, the other one)

Next Week R Programming - PART I