#2. Learn your Working Directory and check files, under your working directory
getwd()
[1] "C:/Users/Asus/Desktop"
list.files()
[1] "~$toğraf Analizleri.docx" "~$yet-mektubu-ornegi-tr.docx" "~$ynakçaa.docx"
[4] "~$YZAK KARAKTER TİPLERİ.docx" "ALL CBS" "ARKEOLOJİK TEORİ"
[7] "AYBE 2019 Bahar" "AYBE 2019 Güz" "Bildiriler"
[10] "delice_GIS" "desktop.ini" "Evraklar"
[13] "final_project.nb.html" "final_project.Rmd" "Foto for CV"
[16] "Google Chrome.lnk" "İLHAN KAYAN" "Java Web Start.lnk"
[19] "PhD_Tezis" "TAY_Project" "WhatsApp.lnk"
[22] "YÖK BURSU" "YÜKSEK LİSANS"
#3. Solve this math. Is your solution bigger than 4 ? TRUE or FALSE.
math<- (5 ^ 3) - (8 * (3/2)) + 4 * (64 ^ 1/2) + 7 ^ (-2 ^ (4.68 - 1/3) )
print (math)
[1] 241
math > 4
[1] TRUE
#4. Create a vector with six numeric and two integer elements, and than assign it to a new variable (vec1)
vector <- c(1,2,3,4,5,6, 1L,2L)
vec1 <- vector
vec1
[1] 1 2 3 4 5 6 1 2
#5. Check the class vec1. Coerce vec1 to be a character vector, assign it as vec2, and check the class vec2
class(vec1)
[1] "numeric"
vec2 <- as.character(vec1)
vec2
[1] "1" "2" "3" "4" "5" "6" "1" "2"
class(vec2)
[1] "character"
#6. Create a vector with eight numeric elements using sequence function, and assign it to a new variable (vec3)
vec <- c(1,2,3,4,5,6,7,8)
vec3 <- vec
vec3 <- seq(1:8)
vec3
[1] 1 2 3 4 5 6 7 8
length(vec3)
[1] 8
mean(vec3)
[1] 4.5
#8. Print the second element of vec3 and change it as "TRUE
print(vec3[2])
[1] 2
vec3[2] <- "TRUE"
vec3[2]
[1] "TRUE"
#9. Create a new vector with 16 elements using the function that generate random uniform numbers, and assign it as vec4.
set.seed(1)
vec4 <- runif(16,20,45)
vec4
[1] 26.63772 29.30310 34.32133 42.70519 25.04205 42.45974 43.61688 36.51994 35.72785 21.54466
[11] 25.14936 24.41392 37.17557 29.60259 39.24604 32.44248
vec4
[1] 26.63772 29.30310 34.32133 42.70519 25.04205 42.45974 43.61688 36.51994 35.72785 21.54466
[11] 25.14936 24.41392 37.17557 29.60259 39.24604 32.44248
#10. Create a new matrix, with 3 rows and 8 columns using vec3 and vec4 by row. Assign it as mat1.
mat1 <- matrix(c(vec3,vec4), nrow = 3, ncol = 8, byrow = TRUE)
mat1
[,1] [,2] [,3] [,4]
[1,] "1" "TRUE" "3" "4"
[2,] "26.6377165785525" "29.3030974909198" "34.3213340837974" "42.7051947498694"
[3,] "35.727851097472" "21.5446567616891" "25.1493643724825" "24.4139188132249"
[,5] [,6] [,7] [,8]
[1,] "5" "6" "7" "8"
[2,] "25.0420482759364" "42.4597421241924" "43.6168817151338" "36.5199448121712"
[3,] "37.1755711664446" "29.6025929553434" "39.2460354999639" "32.4424810521305"
#11. Create a new array with 6 rows, 4 columns and 2 layers using mat1. Assign it as arr1
arr1 <- array(mat1, dim = c(6,4,2))
arr1
#12. Check structure and dimensions of mat1 and arr1
dim(mat1)
dim(arr1)
str(mat1)
chr [1:3, 1:8] "1" "26.6377165785525" "35.727851097472" "TRUE" "29.3030974909198" ...
str(arr1)
chr [1:6, 1:4, 1:2] "1" "26.6377165785525" "35.727851097472" "TRUE" "29.3030974909198" ...
#13. Select 3rd row, 2nd column and change it with NA for each layers
arr1[3,2,] <- NA
arr1
, , 1
[,1] [,2] [,3] [,4]
[1,] "1" "3" "5" "7"
[2,] "26.6377165785525" "34.3213340837974" "25.0420482759364" "43.6168817151338"
[3,] "35.727851097472" NA "37.1755711664446" "39.2460354999639"
[4,] "TRUE" "4" "6" "8"
[5,] "29.3030974909198" "42.7051947498694" "42.4597421241924" "36.5199448121712"
[6,] "21.5446567616891" "24.4139188132249" "29.6025929553434" "32.4424810521305"
, , 2
[,1] [,2] [,3] [,4]
[1,] "1" "3" "5" "7"
[2,] "26.6377165785525" "34.3213340837974" "25.0420482759364" "43.6168817151338"
[3,] "35.727851097472" NA "37.1755711664446" "39.2460354999639"
[4,] "TRUE" "4" "6" "8"
[5,] "29.3030974909198" "42.7051947498694" "42.4597421241924" "36.5199448121712"
[6,] "21.5446567616891" "24.4139188132249" "29.6025929553434" "32.4424810521305"
df1 <- data.frame (vec1, vec2, vec3)
df1
print(df1[,2])
[1] 1 2 3 4 5 6 1 2
Levels: 1 2 3 4 5 6
#15. Create a list with vec1, mat1, arr1 and df1. Assign it as list1. Print 4th element of list1.
list1 <- list(vec1, mat1, arr1, df1)
list1
[[1]]
[1] 1 2 3 4 5 6 1 2
[[2]]
[,1] [,2] [,3] [,4]
[1,] "1" "TRUE" "3" "4"
[2,] "26.6377165785525" "29.3030974909198" "34.3213340837974" "42.7051947498694"
[3,] "35.727851097472" "21.5446567616891" "25.1493643724825" "24.4139188132249"
[,5] [,6] [,7] [,8]
[1,] "5" "6" "7" "8"
[2,] "25.0420482759364" "42.4597421241924" "43.6168817151338" "36.5199448121712"
[3,] "37.1755711664446" "29.6025929553434" "39.2460354999639" "32.4424810521305"
[[3]]
, , 1
[,1] [,2] [,3] [,4]
[1,] "1" "3" "5" "7"
[2,] "26.6377165785525" "34.3213340837974" "25.0420482759364" "43.6168817151338"
[3,] "35.727851097472" NA "37.1755711664446" "39.2460354999639"
[4,] "TRUE" "4" "6" "8"
[5,] "29.3030974909198" "42.7051947498694" "42.4597421241924" "36.5199448121712"
[6,] "21.5446567616891" "24.4139188132249" "29.6025929553434" "32.4424810521305"
, , 2
[,1] [,2] [,3] [,4]
[1,] "1" "3" "5" "7"
[2,] "26.6377165785525" "34.3213340837974" "25.0420482759364" "43.6168817151338"
[3,] "35.727851097472" NA "37.1755711664446" "39.2460354999639"
[4,] "TRUE" "4" "6" "8"
[5,] "29.3030974909198" "42.7051947498694" "42.4597421241924" "36.5199448121712"
[6,] "21.5446567616891" "24.4139188132249" "29.6025929553434" "32.4424810521305"
[[4]]
print(list1[4])
[[1]]
vec1 vec2 vec3
1 1 1 1
2 2 2 TRUE
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 1 1 7
8 2 2 8
#16. Go to main web page and download Istanbul_Cekmekoy_Omerli_26072017-29072017_15min.txt in your working directory and Read the station data in R-Studio (be careful about file path, header and seperator). Assign it as ****
getwd()
[1] "C:/Users/Asus/Desktop"
omerli <- read.csv("Istanbul_Cekmekoy_Omerli_26072017-29072017_15min -txt", sep=";")
sta_data1 <- omerli<- read.csv("Istanbul_Cekmekoy_Omerli_26072017-29072017_15min -txt", sep=";")
sta_data1
#17. Check the structure and attributes of sta_data. Print and plot the precipiptation and temperature of sta_data1
str(sta_data1)
'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 ...
attributes(sta_data1)
$names
[1] "sta_no" "year" "month" "day"
[5] "hour" "minutes" "temp" "precipitation"
[9] "pressure" "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 20 21 22 23
[24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
[47] 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
[70] 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
[93] 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
[116] 116 117 118 119 120 121
print(sta_data1)
plot(sta_data1$temp)
plot(sta_data1$precipitation)
#18. Change temperature with NA if the value is lower than 20. Assign it as sta_data2
Temp <- c(sta_data1$temp)
Temp
[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 21.7 21.9 21.7
[19] 21.6 22.2 22.2 22.1 22.3 22.5 22.3 22.2 22.5 22.6 22.6 22.6 22.6 22.7 22.6 22.5 22.6 22.5
[37] 22.5 22.4 22.5 22.4 22.5 22.6 23.0 23.2 24.2 25.1 25.5 26.1 27.1 26.9 27.6 28.0 28.4 28.5
[55] 29.3 30.2 30.1 30.1 30.4 30.4 30.8 30.9 31.0 31.5 31.2 30.9 30.9 30.4 30.4 30.0 29.2 29.5
[73] 29.4 29.3 29.6 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 20.6 20.6 20.5
[109] 20.7 20.8 20.4 20.4 20.6 20.5 20.4 20.5 20.5 20.6 20.5 20.5 20.4
plot(Temp, main = "sta_data1" , type = "l", xlab = "")
#19. Write sta_data2 as a new txt file in your working directory.
write.table(sta_data2, file = "Istanbul_Cekmekoy_Omerli_26072017-29072017_15min -txt")
list.files()
[1] "~$toğraf Analizleri.docx"
[2] "~$yet-mektubu-ornegi-tr.docx"
[3] "~$ynakçaa.docx"
[4] "~$YZAK KARAKTER TİPLERİ.docx"
[5] "ALL CBS"
[6] "ARKEOLOJİK TEORİ"
[7] "AYBE 2019 Bahar"
[8] "AYBE 2019 Güz"
[9] "Bildiriler"
[10] "delice_GIS"
[11] "desktop.ini"
[12] "Evraklar"
[13] "final_project.nb.html"
[14] "final_project.Rmd"
[15] "Foto for CV"
[16] "Google Chrome.lnk"
[17] "İLHAN KAYAN"
[18] "Istanbul_Cekmekoy_Omerli_26072017-29072017_15min -txt"
[19] "Java Web Start.lnk"
[20] "PhD_Tezis"
[21] "station.txt"
[22] "TAY_Project"
[23] "WhatsApp.lnk"
[24] "YÖK BURSU"
[25] "YÜKSEK LİSANS"
#20. Install “ncdf4” package and call it into R-Studio from library.
install.packages("ncdf4")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
Installing package into 㤼㸱C:/Users/Asus/Documents/R/win-library/3.6㤼㸲
(as 㤼㸱lib㤼㸲 is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/ncdf4_1.17.zip'
Content type 'application/zip' length 3270524 bytes (3.1 MB)
downloaded 3.1 MB
package ‘ncdf4’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Asus\AppData\Local\Temp\Rtmp46m2y1\downloaded_packages
library(ncdf4)