precip Data Frame (by time and station)

date <- unique(data[, 6])                      #date
date <- format(sort(date))                     #sorting dates and converting from numeric to char string
date2 <- as.Date(date, format = "%Y%m%d")      #converting dates into proper date format
station_ids_names <- unique(data[, 1:2])       #station ids
station_names <- station_ids_names[, 2]
precip <- matrix(NA, nrow = length(date), 
                 ncol = length(station_names)) #create empty matrix
precip <- as.data.frame(precip)                #matrix to data frame
names(precip) <- station_names                 #adding column station names to empty precip data frame
row.names(precip) <- date                      #adding row dates to empty precip data frame
for (i in 1:length(station_names)){            #loop goes through all 36 stations
  station_ind = data[, 2] == station_names[i]  #row is True for station i and False if not
  station_date <- format(data[station_ind, 6]) #dates for station i converted from numeric to character string
  ind <- match(station_date, date)             #checking that dates match
  precip[ind, i] <- data[station_ind, 7]       #updating/adding precipitation to precip data
}
write.csv(precip, "~/Desktop/ENSO/Data_Frames/precip.csv")

temps_min Data Frame (by time and station)

temps_min <- matrix(NA, nrow = length(date), 
                    ncol = length(station_names)) #create empty matrix
temps_min <- as.data.frame(temps_min)             #matrix to data frame
names(temps_min) <- station_names                 #adding column station ids to empty temps_min data frame
row.names(temps_min) <- date                      #adding row dates to empty temps_min data frame
for (i in 1:length(station_names)){               #loop goes through all 36 stations
  station_ind = data[, 2] == station_names[i]     #row is True for station i and False if not
  station_date <- format(data[station_ind, 6])    #dates for station i converted from numeric to character string
  ind <- match(station_date, date)                #checking that dates match
  temps_min[ind, i] <- data[station_ind, 9]       #updating/adding minimum temperatures to temps_min data
}
write.csv(temps_min, "~/Desktop/ENSO/Data_Frames/temps_min.csv")

temps_max Data Frame (by time and station)

temps_max <- matrix(NA, nrow = length(date), 
                    ncol = length(station_names)) #create empty matrix
temps_max <- as.data.frame(temps_max)             #matrix to data frame
names(temps_max) <- station_names                 #adding column station ids to empty temps_max data frame
row.names(temps_max) <- date                      #adding row dates to empty temps_max data frame
for (i in 1:length(station_names)){               #loop goes through all 36 stations
  station_ind = data[, 2] == station_names[i]     #row is True for station i and False if not
  station_date <- format(data[station_ind, 6])    #dates for station i converted from numeric to char string
  ind <- match(station_date, date)                #checking that dates match
  temps_max[ind, i] <- data[station_ind, 8]       #updating/adding maximum temperatures to temps_max data
}
write.csv(temps_max, "~/Desktop/ENSO/Data_Frames/temps_max.csv")