├── assets ├── Tutorial1.PNG ├── Tutorial2.PNG ├── Tutorial3.PNG ├── Tutorial4.PNG └── 440b1e66804e59bf801b9d37ead168e86cae0339b0853ad67da867825ed59c1b.jfif ├── 10 - Reading External Data ├── data │ ├── FBI Crime Data.xls │ └── NYC temperature data.csv ├── 02 - Reading Data From SQL.R └── 01 - Loading external data (Excel-CSV).R ├── 2 - Vectors ├── Bonus - The Environment.R ├── 03 - Vector Modification.R ├── 02 - Vector Indexing and Names Property.R └── 01 - Vectors and Variable Assignment.R ├── 4 - Arrays ├── 02 - Indexing and Modifying Arrays.R ├── 03 - Operations with Arrays.R ├── 05 - Combining Arrays.R ├── 01 - Creating Arrays.R └── 04 - Dimnames Property.R ├── 7 - Lists ├── 04 - Combining Lists.R ├── 03 - Adding or Removing List Elements.R ├── 02 - Indexing R Lists.R └── 01 - Creating R Lists.R ├── 6 - DataFrames ├── 04 - Removing Rows or Columns.R ├── 03 - Expanding Data Frames.R ├── 01 - Data Frames Creation.R └── 02 - Data Frames Indexing and Selection.R ├── 1 - R as a Calculator └── 01 - Using R as a Calculator.R ├── 5 - Matrices ├── 02 - Matrix Operations.R └── 01 - Matrices.R ├── 3 - Data Types ├── 03 - Dates.R ├── 02 - Factors.R └── 01 - Variable Types.R ├── 9 - Working with Data Frames ├── 08 - Merging using SQLDF.R ├── 03 - Creating a New Column.R ├── 06 - Aggregating and Sorting.R ├── 01 - Inspecting data.R ├── 02 - Filtering Data.R ├── 07 - Merging DataFrames.R ├── 09 - Plotting.R ├── 05 - Creating a New Column with Sapply.R └── 04 - Apply Family.R ├── 8 - Libraries └── 1 - Installing and Loading Libraries.R ├── 11 - Functions ├── 02 - Combining Functions and Data.R └── 01 - Functions Examples.R ├── readme.md └── LICENSE /assets/Tutorial1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/assets/Tutorial1.PNG -------------------------------------------------------------------------------- /assets/Tutorial2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/assets/Tutorial2.PNG -------------------------------------------------------------------------------- /assets/Tutorial3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/assets/Tutorial3.PNG -------------------------------------------------------------------------------- /assets/Tutorial4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/assets/Tutorial4.PNG -------------------------------------------------------------------------------- /10 - Reading External Data/data/FBI Crime Data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/10 - Reading External Data/data/FBI Crime Data.xls -------------------------------------------------------------------------------- /assets/440b1e66804e59bf801b9d37ead168e86cae0339b0853ad67da867825ed59c1b.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivopbernardo/r-programming-absolute-beginners/HEAD/assets/440b1e66804e59bf801b9d37ead168e86cae0339b0853ad67da867825ed59c1b.jfif -------------------------------------------------------------------------------- /2 - Vectors/Bonus - The Environment.R: -------------------------------------------------------------------------------- 1 | # In this script we explore the environment 2 | # and objects 3 | 4 | # Creating variables is done by assignment: 5 | my_vector <- c(1,2,3,4) 6 | 7 | # Removing specific objects from the environment can be done with rm: 8 | rm(my_vector) 9 | 10 | # Listing all variables available in the environment 11 | ls() 12 | 13 | # Objects can also be simple strings 14 | char_var <- 'abc' 15 | 16 | # Using a combination of rm and ls will clean all variables 17 | # in the environment 18 | rm(list = ls()) -------------------------------------------------------------------------------- /4 - Arrays/02 - Indexing and Modifying Arrays.R: -------------------------------------------------------------------------------- 1 | # In this scripts, we will explore indexing and 2 | # modifying arrays. 3 | 4 | # Creating our example array 5 | example_array <- array(1:8, dim = c(2,2)) 6 | 7 | # Accessing all the elements from the first dimension 8 | example_array[1,] 9 | 10 | # Acessing all the elements from the second dimension 11 | example_array[,1] 12 | 13 | # Acessing specific elements 14 | example_array[1,1] 15 | 16 | # Just like vectors, we can use indexing to 17 | # change elements inside the array 18 | example_array[1,1] <- 100 19 | -------------------------------------------------------------------------------- /4 - Arrays/03 - Operations with Arrays.R: -------------------------------------------------------------------------------- 1 | # Operations with Arrays 2 | 3 | # Creating our example array 4 | my_array <- array(1:4, dim=c(2,2)) 5 | 6 | # Similar to vectors, we can also apply 7 | # functions to our arrays 8 | # the functions will also be applied element-wise 9 | sqrt(my_array) 10 | 11 | # We can also apply functions to specific 12 | # array elements using indexes 13 | sqrt(my_array[1,]) 14 | 15 | # Also, simple mathematical operations can be applied 16 | # to our objects, such as: 17 | 18 | my_array+5 19 | 20 | my_array / 2 21 | 22 | my_array - 10 23 | 24 | -------------------------------------------------------------------------------- /7 - Lists/04 - Combining Lists.R: -------------------------------------------------------------------------------- 1 | # Combining lists can be achieved with the c() function! 2 | 3 | # Creating list 1 with elements regarding Spain 4 | country_temperatures = list( 5 | "country"="Spain","months"=c("Jan","Fev","Mar"), "temperatures"=c(10,12,13) 6 | ) 7 | 8 | 9 | # Creating list 2 with elements regarding France 10 | country_temperatures_1 = list("country_1"="France","months_1"=c("Jan","Fev","Mar"), "temperatures_1"=c(12.5,12,15)) 11 | 12 | # We can combine these two lists into one single list 13 | # by using the c() command 14 | c(country_temperatures,country_temperatures_1) 15 | -------------------------------------------------------------------------------- /2 - Vectors/03 - Vector Modification.R: -------------------------------------------------------------------------------- 1 | # In this script we are going to 2 | # experiment a bit with vector modifications 3 | 4 | # Creating a vector called bananas that represents 5 | # "weights of bananas" 6 | bananas <- c(1.2, 1.4, 2.4, 3.4) 7 | 8 | # Rewriting the first banana weight 9 | melons[1] <- 1.8 10 | 11 | # Rewriting multiple elements at the same time: 12 | melons[c(3,4)] <- c(4,4) 13 | 14 | # Adding a new element by providing a new index: 15 | melons[5] <- 3 16 | 17 | # Rewriting based on condition 18 | melons[melons < 2] <- 0 19 | 20 | # Removing elements using - 21 | new_melons <- melons[-c(1,5)] -------------------------------------------------------------------------------- /6 - DataFrames/04 - Removing Rows or Columns.R: -------------------------------------------------------------------------------- 1 | # We can also remove some rows or columns from data frames 2 | 3 | countries_data <- data.frame(country=c("Portugal","France","UK"), 4 | population = c(10280000,66990000,66650000), 5 | EU= c(TRUE,TRUE,FALSE)) 6 | 7 | # Example on how to remove rows - in this case 8 | # we are removing the third row (UK) 9 | 10 | # Notice that we can only remove rows with the "-" by referring 11 | # the numeric index, which is a setback 12 | countries_data <- countries_data[-3,] 13 | 14 | # Example on how to remove columns - in this case 15 | # the EU column 16 | countries_data[, 'EU'] <- NULL 17 | 18 | -------------------------------------------------------------------------------- /7 - Lists/03 - Adding or Removing List Elements.R: -------------------------------------------------------------------------------- 1 | # Adding or removing list elements is relatively easy. 2 | 3 | # Starting by creating an example_list: 4 | example_list <- list(c('a','b','c'), array(1:10, dim=c(2,5))) 5 | 6 | # We can add elements by positioning them 7 | # in a new index that doesn't exist - in the case below we are 8 | # adding a new list element with the character 'abc'. 9 | example_list[3] <- 'abc' 10 | 11 | # To add / remove elements, it's sufficient to access the high-level 12 | # representation of the underlying object. A single pair of square 13 | # brackets does the job! 14 | 15 | # To remove elements from list we can assign them to 16 | # the element NULL 17 | example_list[3] <- NULL -------------------------------------------------------------------------------- /1 - R as a Calculator/01 - Using R as a Calculator.R: -------------------------------------------------------------------------------- 1 | # Shortcut to run commands > ctrl+enter 2 | 3 | # Basic Operations - Using R as a Calculator 4 | # Comments in R are done using the # - 5 | # this line and the above will not be compiled as code 6 | 7 | # Adding values 8 | 1 + 1 9 | 10 | # Subtracting values 11 | 10 - 5 12 | 13 | # Subtracting floats 14 | 10-5.3 15 | 16 | # Division 17 | 10 / 2 18 | 19 | # Multiplication 20 | 2 * 3 21 | 22 | # Square Roots 23 | sqrt(9) 24 | 25 | # Exponentials 26 | exp(1) 27 | 28 | # Logarithms 29 | log(2) 30 | 31 | # Powers 32 | 4**2 33 | 34 | # More Complex Calculations using 35 | # Mathematical Order of Operations 36 | (10+10)/(2**2) 37 | 38 | (log(3)/100)/sqrt(9) 39 | 40 | # In a nutshell, R respects all mathematical rules 41 | # we know! 42 | -------------------------------------------------------------------------------- /6 - DataFrames/03 - Expanding Data Frames.R: -------------------------------------------------------------------------------- 1 | # After creating data frames, we can change them by adding new rows 2 | # or columns 3 | 4 | # Let's use the countries_data again 5 | countries_data <- data.frame(country=c("Portugal","France","UK"), 6 | population = c(10280000,66990000,66650000), 7 | EU= c(TRUE,TRUE,FALSE)) 8 | 9 | # Creating the same data structure with Spain information 10 | spain_data <- data.frame(country=c("Spain"), 11 | population = c(46754778 ), 12 | EU= c(TRUE)) 13 | 14 | # Add spain's data to countries data with rbind 15 | 16 | countries_data <- rbind(countries_data,spain_data) 17 | 18 | # Adding columns can be done with cbind: 19 | capital = c('Lisbon','Paris','London','Madrid') 20 | countries_data_with_capital = cbind(countries_data,capital) -------------------------------------------------------------------------------- /4 - Arrays/05 - Combining Arrays.R: -------------------------------------------------------------------------------- 1 | # We can combine arrays row-wise or column-wise. 2 | # These properties also apply to data frames, 3 | # another object we will study in the future 4 | 5 | # Let's create two 2-by-2 arrays: 6 | my_array_1 <- array(1:4, dim=c(2,2)) 7 | 8 | my_array_2 <- array(10:14, dim=c(2,2)) 9 | 10 | # to combine the elements row wise: 11 | rbind(my_array_1, my_array_2) 12 | 13 | # to combine the elements column wise 14 | cbind(my_array_1, my_array_2) 15 | 16 | # Watch out for different number of dimensions 17 | # when combining arrays! 18 | 19 | # Creating a 10 by 4 2D array: 20 | my_different_array <- array(10:14, dim=c(10,4)) 21 | 22 | # The following will throw an error due to a mismatch 23 | # in the number of columns or rows of the arrays: 24 | rbind(my_different_array, my_array_1) 25 | 26 | cbind(my_different_array, my_array_1) 27 | 28 | -------------------------------------------------------------------------------- /5 - Matrices/02 - Matrix Operations.R: -------------------------------------------------------------------------------- 1 | # With matrices, we can also perform sum interesting 2 | # calculations 3 | 4 | example_matrix <- matrix(data=1:4, nrow=2, ncol=2) 5 | example_matrix_2 <- matrix(data=4:7, nrow=2, ncol=2) 6 | 7 | # Adding two matrices 8 | example_matrix + example_matrix_2 9 | 10 | # Subtracting two matrices 11 | example_matrix - example_matrix_2 12 | 13 | # Running with elements that don't fit the 14 | # matrix yields a warning 15 | four_col_matrix <- matrix(data=4:8, nrow=2, ncol=4) 16 | 17 | # Simple multiplication yields an error - this is the element 18 | # wise multiplication, formally called Hadamard Product 19 | example_matrix * four_col_matrix 20 | 21 | # With %*% we perform the dot product of two matrices. 22 | # In the dot product, the inner dimensions must match so applying 23 | # the code below does not yield an error: 24 | example_matrix %*% four_col_matrix 25 | -------------------------------------------------------------------------------- /4 - Arrays/01 - Creating Arrays.R: -------------------------------------------------------------------------------- 1 | # Arrays are really cool multi-dimensional objects 2 | # that enable us to extend the power of vectors 3 | 4 | # Example on creating an array with 2 dimensions 5 | # and two elements on each dimension 6 | my_array <- array(1:4, dim = c(2,2)) 7 | 8 | # Checking the class of our array 9 | class(my_array) 10 | 11 | # 2D arrays are matrix class (which are a special 12 | # type of array) - one-d arrays will be of type 13 | # array 14 | my_array <- array(1:4, dim = c(2)) 15 | 16 | class(my_array) 17 | 18 | # Using the Dim command to check the dimensions and number 19 | # of elements of our array 20 | dim(my_array) 21 | 22 | # Showing typeof just as an example 23 | typeof(my_array) 24 | 25 | # Our dimensions don't stop at 2! we can raise 26 | # the number of dimensions of array - for example 27 | # creating a 3-D array: 28 | my_array <- array(1:4, dim = c(2,2,2)) 29 | 30 | # And checking the class of our 3D array 31 | class(my_array) 32 | -------------------------------------------------------------------------------- /5 - Matrices/01 - Matrices.R: -------------------------------------------------------------------------------- 1 | # We've already checked matrices in the arrays section 2 | # Matrices are basically 2D arrays! 3 | 4 | # In this script, we are going to check how 5 | # to create matrices with the special matrix() constructor 6 | 7 | # Creating a matrix using matrix() and array() 8 | # functions will produce the same results 9 | 10 | example_matrix <- array(1:4, dim=c(2,2)) 11 | 12 | example_matrix_2 <- matrix(data=1:4, nrow=2, ncol=2) 13 | 14 | # Comparing the two 15 | example_matrix == example_matrix_2 16 | 17 | # Checking some attributes of matrices, similar to what we've seen 18 | # with arrays 19 | dim(example_matrix_2) 20 | 21 | nrow(example_matrix_2) 22 | ncol(example_matrix_2) 23 | 24 | class(example_matrix_2) 25 | 26 | # With the matrix constructor, we can 27 | # access some new arguments in the functions 28 | # for example, byrow fills the matrix with different orientation 29 | example_matrix_2 <- matrix(data=1:4, nrow=2, ncol=2, byrow=TRUE) -------------------------------------------------------------------------------- /3 - Data Types/03 - Dates.R: -------------------------------------------------------------------------------- 1 | # Dates are another interesting type of data 2 | 3 | dates <- as.Date(c('2007-02-01', '2007-02-02')) 4 | 5 | # Checking class and typeof our dates 6 | 7 | class(dates) 8 | typeof(dates) 9 | 10 | # Dates are stored as integers - the number of days 11 | # since 1 Jan 1970 12 | as.numeric(dates) 13 | 14 | # We can also feed date formats in the conversion, depending 15 | # on the format we have on our dates 16 | dates_f1 <- as.Date(c('02/01/2007', '02/02/2007'), format="%m/%d/%Y") 17 | 18 | # Another type of format 19 | dates_f2 <- as.Date(c('01202009'), format="%M%d%Y") 20 | 21 | # if we have year as lowercase the format expects 22 | # a two digit year and it gets the date wrong 23 | dates_f3 <- as.Date(c('01202009'), format="%M%d%y") 24 | 25 | # To extract the month 26 | format(dates_f1, '%m') 27 | 28 | # And extracting the year 29 | format(dates_f1, '%Y') 30 | 31 | # A nice resource on date formats 32 | # https://www.r-bloggers.com/2013/08/date-formats-in-r/ 33 | -------------------------------------------------------------------------------- /9 - Working with Data Frames/08 - Merging using SQLDF.R: -------------------------------------------------------------------------------- 1 | # We can combine tables using typical SQL Code 2 | # If you are more used to use SQL code, this can be a 3 | # good way for you to start adapting to R code 4 | 5 | # Loading mtcars 6 | data(mtcars) 7 | 8 | # Creating the car brand to help us on the merge 9 | mtcars$model <- rownames(mtcars) 10 | car_list <- strsplit(mtcars$model, ' ') 11 | mtcars$brand <- sapply(car_list, '[', 1) 12 | 13 | # Creating the brands origin again 14 | brands_origin <- data.frame( 15 | brand = c("Mazda","Toyota","Fiat","Volvo","Skoda"), 16 | country = c("Japan","Japan", "Italy", "Sweden","Czech Republic") 17 | ) 18 | 19 | # We can use the SQLDF library - This is an example of an Inner merge 20 | # but using the SQL syntax 21 | 22 | install.packages('sqldf') 23 | 24 | library(sqldf) 25 | 26 | # Using SQL code inside R 27 | df_result <- sqldf("SELECT a.*, b.* 28 | FROM mtcars as a 29 | INNER JOIN brands_origin as b USING(brand)") 30 | -------------------------------------------------------------------------------- /9 - Working with Data Frames/03 - Creating a New Column.R: -------------------------------------------------------------------------------- 1 | # We'll check the mtcars dataset again 2 | data(mtcars) 3 | 4 | # Adding a new column is easy - just like 5 | # other objects, we provide a new element to the new element 6 | # we want to create. In this case, we are using the dollar-sign notation 7 | # to state that we want the column hp_wt to be made of the ratio between 8 | # the hp and wt columns. 9 | mtcars$hp_wt <- mtcars$hp/mtcars$wt 10 | 11 | # Another way to do it with a different indexer method: 12 | mtcars['hp_wt'] <- mtcars[,'hp']/mtcars[,'wt'] 13 | 14 | # We can apply other kinds of functions to columns, 15 | # just as we've done in vectors - example of squaring or applying the square root: 16 | mtcars$miles_gallon_squared <- mtcars$mpg**2 17 | mtcars$sqrt_hp <- sqrt(mtcars$hp) 18 | 19 | # As long as the element we are passing contains the same number 20 | # of rows of the dataframe, we are ok! For example, we can pass 21 | # the rownames into a column: 22 | mtcars$model <- rownames(mtcars) -------------------------------------------------------------------------------- /9 - Working with Data Frames/06 - Aggregating and Sorting.R: -------------------------------------------------------------------------------- 1 | # Aggregating and sorting are other common operations 2 | # one does with dataframes in R 3 | data(mtcars) 4 | 5 | # Creating the car brand to help us on the aggregation 6 | mtcars$model <- rownames(mtcars) 7 | car_list <- strsplit(mtcars$model, ' ') 8 | mtcars$brand <- sapply(car_list, '[', 1) 9 | 10 | # Let's aggregate our data so we can check 11 | # the mean of horsepower by each car_brand 12 | 13 | # This can be achieved using the aggregate function: 14 | agg_brands <- aggregate( 15 | mtcars$hp, 16 | by = list(mtcars$brand), 17 | FUN=mean 18 | ) 19 | 20 | # we can set the colnames after or in the creation 21 | # of the aggregate with the function setnames() 22 | colnames(agg_brands) <- c('brand','mean_hp') 23 | 24 | # Sorting in an ascending way is simple, we just need to 25 | # pass order to row indexer: 26 | agg_brands[order(agg_brands[,'mean_hp']),] 27 | 28 | # We can also sort our table in a descending way 29 | agg_brands[order(-agg_brands[,'mean_hp']),] 30 | -------------------------------------------------------------------------------- /7 - Lists/02 - Indexing R Lists.R: -------------------------------------------------------------------------------- 1 | # Indexing lists is pretty easy 2 | 3 | # Let's create a multiple object list and assign different 4 | # names to the elements: 5 | multi_object <- list( 6 | c(1,2,3), 7 | matrix(c(1,2,3,4), ncol=2, nrow=2), 8 | list(TRUE,0,'C') 9 | ) 10 | 11 | # Assigning Names 12 | names(multi_object)= c('Vector','Matrix','List') 13 | 14 | # If we want to retrieve the Vector that is stored 15 | # in the first position of the list, we have to use the 16 | # double square brackets: [[]] 17 | multi_object[["Vector"]] 18 | 19 | # This is a special case in R programming. The [[]] enables us 20 | # to access the underlying object and manipulate the elements on that 21 | # object. If we only use a single pair of square brackets, we will only 22 | # access a high-level representation of that object that won't let us 23 | # manipulate it. 24 | 25 | # The same reasoning applies if we use numeric indexes: 26 | multi_object[[1]] 27 | 28 | # We can also retrieve by a new syntax - the dollar sign notation 29 | multi_object$Vector -------------------------------------------------------------------------------- /10 - Reading External Data/02 - Reading Data From SQL.R: -------------------------------------------------------------------------------- 1 | # Loading data from Databases 2 | # You can only run this piece of code if you 3 | # set up a odbc datasource in your operating system 4 | # in this example, I'm using a MYSQL database 5 | 6 | # install mysql: 7 | # https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/ 8 | 9 | # Setup odbc data source: 10 | # https://kb.iu.edu/d/amsw 11 | 12 | # Databases are one of the common systems used in organizations 13 | # to store data and move files around - R has some cool libraries that 14 | # we can use to load tables directly from SQL 15 | 16 | # Install package RODBC 17 | install.packages("RODBC") 18 | 19 | # Load the RODBC library 20 | library(RODBC) 21 | 22 | # Open Channel to Database 23 | channel <- odbcConnect("mysqlconn", uid="root") 24 | 25 | # Get result using a query - this will load the table directly into a dataframe 26 | result1 <- sqlQuery(channel, paste("SELECT * from sakila.city")) 27 | 28 | # Always a good idea to close the connection after working with the 29 | # data in R 30 | close(channel) -------------------------------------------------------------------------------- /9 - Working with Data Frames/01 - Inspecting data.R: -------------------------------------------------------------------------------- 1 | # This scripts reads a dataset and performs 2 | # some basic and common operations with data. 3 | 4 | # Later we will learn how to import external datasets to R - for now let's learn a bit 5 | # about some of the internal datasets that R has available for us to play with 6 | 7 | # Let's take a look at the data() command to check the datasets we have available 8 | data() 9 | 10 | # We'll check the mtcars dataset first - a really famous dataset 11 | data(mtcars) 12 | 13 | # Calling ? on this dataset gives us more documentation and information 14 | # about columns 15 | 16 | ?mtcars 17 | 18 | # checking first and bottom rows is easy with the head() and tail() commands 19 | head(mtcars, 5) 20 | 21 | tail(mtcars, 5) 22 | 23 | # Structure provides us information about the structure 24 | str(mtcars) 25 | 26 | # Some properties of the dataset include nrow, ncol and names, functions 27 | # we already seen applied in other objects. 28 | nrow(mtcars) 29 | 30 | ncol(mtcars) 31 | 32 | names(mtcars) 33 | 34 | # The powerful summary command: 35 | summary(mtcars) 36 | -------------------------------------------------------------------------------- /9 - Working with Data Frames/02 - Filtering Data.R: -------------------------------------------------------------------------------- 1 | # For this script, 2 | # we'll check the mtcars dataset again 3 | data(mtcars) 4 | 5 | # Filtering the table - Selecting only the cars with 6 | # cyl equals to 4. 7 | 8 | # The logic is simple, we pass the subset filter to the 9 | # row indexer of the dataframe. Recall that the indexer 10 | # before the comma is related with the rows, 1st dimension 11 | mtcars[mtcars$cyl==4,] 12 | 13 | # We can ask for all 4 with cylinders different than 4 by switching 14 | # the condition inside the indexer. != means different than 15 | mtcars[mtcars$cyl!=4,] 16 | 17 | # Multiple selections can be achieved with %in%: 18 | method_1 <- mtcars[mtcars$cyl %in% c(4,6),] 19 | 20 | # Another way to do it is to provide | (or condition). This 21 | # has the downside of not scalling very well when we have a lot 22 | # of conditions so %in% is prefered. 23 | method_2 <- mtcars[(mtcars$cyl==4) | (mtcars$cyl==6),] 24 | 25 | # Are these objects the same? 26 | method_1==method_2 27 | 28 | # We can also provide an and (&) clause to the indexer 29 | mtcars[(mtcars$hp>100) & (mtcars$hp<140),] -------------------------------------------------------------------------------- /6 - DataFrames/01 - Data Frames Creation.R: -------------------------------------------------------------------------------- 1 | # Data Frames are objects similar to tables in excel 2 | # or tables you would find on databases 3 | 4 | # Let's create a countries_data dataframe with three columns, country 5 | # population and EU 6 | countries_data <- data.frame(country=c("Portugal","France","UK"), 7 | population = c(10280000,66990000,66650000), 8 | EU= c(TRUE,TRUE,FALSE)) 9 | 10 | # Data frames are the most famous way to work with data in R. 11 | # Rows are organized in columns and rows, similar to a 2 dimension matrix 12 | 13 | countries_data 14 | 15 | # Some properties we can extract: 16 | nrow(countries_data) 17 | 18 | ncol(countries_data) 19 | 20 | dim(countries_data) 21 | 22 | # Let's see the class and typeof a dataframe: 23 | class(countries_data) 24 | typeof(countries_data) 25 | 26 | # We can also use the row.names property to assign names 27 | # to our rows 28 | 29 | countries_data <- data.frame( 30 | population = c(10280000,66990000,66650000), 31 | EU= c(TRUE,TRUE,FALSE), 32 | row.names = c("Portugal","France","UK")) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /8 - Libraries/1 - Installing and Loading Libraries.R: -------------------------------------------------------------------------------- 1 | # Libraries are one important component of the language 2 | # For example, let me try to access the ggplot() function 3 | # that does plots in R 4 | 5 | ggplot() 6 | 7 | # the code above yields an error - this is because this function 8 | # is only accessible after installing and loading the ggplot2 package 9 | # in the environment. 10 | 11 | # in the context of R, package and library are terms that mean the same 12 | # thing and are used exchangeably. They mean that we want to use 13 | # external code that needs to be installed/imported 14 | 15 | # Installing Libraries using code is easy with the install.packages 16 | # function: 17 | install.packages('ggplot2') 18 | 19 | # You can also install 20 | # using the R Studio UI in Tools -> Install Packages 21 | 22 | # To load a library you can use 23 | library(ggplot2) 24 | 25 | # Only after loading this library can you access 26 | # the functions that are available in the library 27 | # Library loading is normally called in the beginning 28 | # of each program 29 | 30 | # Now running ggplot() will not yield an error (even without arguments): 31 | ggplot() -------------------------------------------------------------------------------- /6 - DataFrames/02 - Data Frames Indexing and Selection.R: -------------------------------------------------------------------------------- 1 | # Creating our Data Frame again 2 | countries_data <- data.frame(country=c("Portugal","France","UK"), 3 | population = c(10280000,66990000,66650000), 4 | EU= c(TRUE,TRUE,FALSE)) 5 | 6 | # Selecting the first row using a numeric index 7 | countries_data[1 ,] 8 | 9 | 10 | # Selecting the first column using a numeric index 11 | countries_data[,1] 12 | 13 | # Indexing rows and columns in dataframes is similar 14 | # to matrices 15 | 16 | # Let's create a new df with row names 17 | countries_data_rownames <- data.frame( 18 | population = c(10280000,66990000,66650000), 19 | EU= c(TRUE,TRUE,FALSE), 20 | row.names=c("Portugal","France","UK")) 21 | 22 | # We can now index by names as well: 23 | countries_data_rownames['Portugal',] 24 | 25 | countries_data_rownames[,'population'] 26 | 27 | # We can also change elements using indexes 28 | # just as we did in arrays and matrixes 29 | 30 | # In the example below, we will change Portugal's population to 1 31 | countries_data_rownames['Portugal','population'] <- 1 -------------------------------------------------------------------------------- /2 - Vectors/02 - Vector Indexing and Names Property.R: -------------------------------------------------------------------------------- 1 | # Let's start by creating Countries Vector with population numbers 2 | 3 | countries <- c(10276617,67545757,67020000) 4 | 5 | # Visualizing our numbers 6 | countries 7 | 8 | # How many countries do we have? - length can help us 9 | 10 | length(countries) 11 | 12 | # Sorting vectors can be done with sort() 13 | sort(countries) 14 | 15 | # In ascending Order, by providing a new argument 16 | sort(countries, decreasing=TRUE) 17 | 18 | # We can assign index names to vectors 19 | names(countries) <- c('Portugal','United Kingdom','France') 20 | 21 | # Assessing vector elements by name 22 | countries['Portugal'] 23 | 24 | # And what about multiple countries? 25 | # Will this work? - No 26 | countries['Portugal','United Kingdom'] 27 | 28 | # We have to pass a vector to the index! 29 | countries[c('Portugal','United Kingdom')] 30 | 31 | # We can also access elements by numerical position 32 | countries[1] 33 | 34 | # And also use slicing 35 | countries[1:2] 36 | 37 | # Accessing the last country using the length property 38 | countries[length(countries)] 39 | 40 | # Returning indexes with which function 41 | which(countries > 11000000) 42 | 43 | # If we want the names of the countries that match the condition 44 | # we can use names 45 | names(which(countries > 11000000)) -------------------------------------------------------------------------------- /3 - Data Types/02 - Factors.R: -------------------------------------------------------------------------------- 1 | # Creating labels as Characters 2 | labels = c('Europe','Africa','Europe', 3 | 'North America','South America','Africa') 4 | 5 | # Setting labels as a new data data type - factors 6 | factor_labels = factor(labels) 7 | 8 | # Confirming it's a factor 9 | class(factor_labels) 10 | typeof(factor_labels) 11 | 12 | # Why does typeof returns an integer? 13 | as.integer(factor_labels) 14 | 15 | # Factors are stored internally as integers to make 16 | # it easier to do comparisons (and also for storage 17 | # efficiency) 18 | 19 | # nlevels gives you the number of levels of the 20 | # factor variable 21 | nlevels(factor_labels) 22 | 23 | # Why use factors? 24 | # If some variable is a string, it can take any value. 25 | # with factors it can only take the values you have 26 | # on levels - this is specially helpful if you have a categorical 27 | # variable 28 | # Also it enables ordinal strings - let's see that example next 29 | 30 | # Create a vector of temperature observations 31 | altitude <- c("High", "Low", "High", "Low", "Medium","Low", "Medium") 32 | 33 | # Give levels to it and let R now that is an 34 | # ordinal vector 35 | altitude_vector <- factor(altitude, order = TRUE, 36 | levels = c("Low", "Medium", "High")) 37 | 38 | altitude_vector 39 | 40 | # Confirming the order below: 41 | as.integer(altitude_vector) -------------------------------------------------------------------------------- /9 - Working with Data Frames/07 - Merging DataFrames.R: -------------------------------------------------------------------------------- 1 | # Combining dataframes is another common operation 2 | # First, let's see how we can do this using native R 3 | 4 | # Loading mtcars 5 | data(mtcars) 6 | 7 | # Creating the car brand to help us on the merge 8 | mtcars$model <- rownames(mtcars) 9 | car_list <- strsplit(mtcars$model, ' ') 10 | mtcars$brand <- sapply(car_list, '[', 1) 11 | 12 | # Let's create a brands_origin dataframe that contains the brand 13 | # of the car and the country of origin. 14 | brands_origin <- data.frame( 15 | brand = c("Mazda","Toyota","Fiat","Volvo","Skoda"), 16 | country = c("Japan","Japan", "Italy", "Sweden","Czech Republic") 17 | ) 18 | 19 | # If we want to combine both of these tables, we can use the merge 20 | # command. 21 | # An inner merge can be achieved by default - inner means that 22 | # only cars with brands in both tables will be on the output. 23 | inner_df <- merge(mtcars,brands_origin,by="brand") 24 | 25 | # Left Join can be achieved by passing all.x = TRUE 26 | left_df <- merge(mtcars,brands_origin,by="brand", all.x=TRUE) 27 | 28 | # Right Join can be achieved by passing all.y = TRUE 29 | right_df <- merge(mtcars,brands_origin,by="brand", all.y=TRUE) 30 | 31 | # Full join can be achieved with all = TRUE 32 | # Full join brings all rows, regardless of their presence in 33 | # table a or table b 34 | full_df <- merge(mtcars,brands_origin,by="brand", all=TRUE) -------------------------------------------------------------------------------- /7 - Lists/01 - Creating R Lists.R: -------------------------------------------------------------------------------- 1 | # In this script, we will explore a very flexible R object - the R list! 2 | 3 | # Arrays are very interesting but have a major setback. 4 | # With arrays, we can't hold different types of objects 5 | 6 | # in the example below, the array will be stored as numeric 7 | array(c(1,2,3)) 8 | 9 | # If we have a single element that is a character, the entire array 10 | # will be treated as a character type 11 | my_ar = array(c(1,2,"A")) 12 | typeof(my_ar) 13 | 14 | # What happens with lists? - Lists enable you to have multiple data types 15 | # or even multiple objects 16 | 17 | # The list below contains three types of elements, a single character, 18 | # and two vectors: 19 | 20 | country_temperatures = list( 21 | "country"="Portugal", 22 | "months"=c("Jan","Fev","Mar"), 23 | "temperatures"=c(12.5,20.1,22)) 24 | 25 | # We can even have other objects inside lists, such as 26 | # matrices or lists: 27 | 28 | multi_object <- list( 29 | c(1,2,3), 30 | matrix(c(1,2,3,4), ncol=2, nrow=2), 31 | list(TRUE,0,'C') 32 | ) 33 | 34 | # And we can assign names to our list elements 35 | # even after creating our list: 36 | names(multi_object)= c('Vector','Matrix','List') 37 | 38 | # We can also use the str function to obtain the structure 39 | # of the list object 40 | str(multi_object) 41 | 42 | # And the length, that will give us the number of elements in the list: 43 | length(multi_object) -------------------------------------------------------------------------------- /4 - Arrays/04 - Dimnames Property.R: -------------------------------------------------------------------------------- 1 | # Although it's interesting that we can access our arrays 2 | # using numeric indexes, this is mostly impractical 3 | # for really large arrays 4 | 5 | # Luckily, we can provide names to our dimensions! 6 | 7 | # To fill the names of the dimensions of our array, 8 | # we have to pass a list to dimnames argument. 9 | 10 | # Note: don't worry too much about this new 11 | # type of object (list), we will study it in 12 | # a subsequent section 13 | country_data <- array( 14 | c(200,200,300,340,230,120,540,400), 15 | dim=c(2,2,2), 16 | dimnames= list(c("Portugal","UK"), 17 | c("Population","GDP"), 18 | c("2018","2019"))) 19 | 20 | # Subsetting by named index - for example, extracting 21 | # the Population of Portugal for 2018: 22 | country_data['Portugal','Population','2018'] 23 | 24 | # What if we search for names of elements in the 25 | # dimensions that do not exist? 26 | country_data['France','Population','2018'] 27 | 28 | # Remember you can use dim to obtain the dimensions 29 | # and number of elements in country_data 30 | dim(country_data) 31 | 32 | # We can also replace elements in the arrays using 33 | # the named version: 34 | country_data['Portugal','Population','2019'] <- 20000 35 | 36 | country_data 37 | 38 | # There are other cool properties we can use 39 | # in arrays - for example extracting the number 40 | # of rows and number of columns - the 41 | # size of our first and second dimensions 42 | 43 | # This is more meaningful to two dimensional arrays (matrixes) 44 | nrow(country_data) 45 | ncol(country_data) 46 | -------------------------------------------------------------------------------- /9 - Working with Data Frames/09 - Plotting.R: -------------------------------------------------------------------------------- 1 | # This script reads a dataset and performs 2 | # some plotting using R 3 | # Let's work with the mtcars dataset again 4 | # as we are already familiar with the data 5 | 6 | data(mtcars) 7 | 8 | # Plotting weight and horsepower as a scatter plot 9 | plot(mtcars$wt, mtcars$hp, main='Car Weight vs Horsepower') 10 | 11 | # Table function helps to summarize our data by counting 12 | # the number of rows by the values of a specific variable 13 | count_cyl <- table(mtcars$cyl) 14 | 15 | # We can do barplots with barplot: 16 | barplot(count_cyl, main="Car Distribution", 17 | xlab="Number of cylinders", ylab="Number of Cars", 18 | col = c('red','yellow','salmon')) 19 | 20 | # Cheatsheet for colors 21 | # https://www.nceas.ucsb.edu/sites/default/files/2020-04/colorPaletteCheatsheet.pdf 22 | 23 | # Creating boxplots is also easy with the boxplot function 24 | # Notice that the formula in the arguments is a bit different 25 | boxplot(hp~gear,data=mtcars, main="Distribution") 26 | 27 | # Creating histograms is also easy: 28 | hist(mtcars$hp, breaks=20, col=c('darkgreen')) 29 | 30 | # For plotting, people normally use ggplot2, one of the coolest 31 | # libraries in R (part of the tidyverse universe of packages) 32 | library(ggplot2) 33 | 34 | # ggplot is a modular function that works a bit differently. Here is an example 35 | # of building an histogram of Horse Power and adding a title: 36 | ( 37 | ggplot(mtcars, 38 | aes(x=hp) 39 | ) + geom_histogram(color='black', fill='salmon', binwidth=40) 40 | + ggtitle('Histogram of HorsePower') 41 | ) -------------------------------------------------------------------------------- /9 - Working with Data Frames/05 - Creating a New Column with Sapply.R: -------------------------------------------------------------------------------- 1 | # Here, we will see a more practical use case of the apply family 2 | # of functions. 3 | 4 | # Loading mtcars 5 | data(mtcars) 6 | 7 | # Let's use sapply to create a column with the 8 | # Brand of the car 9 | 10 | # We know that the brand of the car is part of the rownames of 11 | # the mtcars data frame. Let's start by creating the car model as column 12 | mtcars$model <- rownames(mtcars) 13 | 14 | # Now, we can use strsplit to split the brand from model 15 | # As the car brand is the first part of the car brand, we can split 16 | # the car model by a blank space 17 | car_list <- strsplit(mtcars$model, ' ') 18 | 19 | # This will produce a list of vectors, where each 20 | # vector contains the number of elements related to the blank 21 | # spaces in the car brand. 22 | 23 | # Some examples would be: 24 | # - "Mazda RX4" becomes a vector of two elements with "Mazda" and "RX4" 25 | # - "Hornet 4 Drive" becomes a vector of three elements with "Hornet", "4" and "Drive" 26 | 27 | # Given that we know have the car brand in the first position of 28 | # these vectors, we can iterate through them and extract 29 | # the first position. 30 | 31 | # This can be done with the apply family! Although it seems complicatedm 32 | # we can break it down in the instruction below: 33 | mtcars$brand <- sapply(car_list, FUN='[', n=1) 34 | 35 | # In sapply, we are passing car_list as the list to iterate on 36 | # our function is '[', which is an indexer function (instead of using an aggregator function 37 | # such as mean or max). 38 | # n=1 means that we are trying to index the first element of all of our sub-vectors. -------------------------------------------------------------------------------- /3 - Data Types/01 - Variable Types.R: -------------------------------------------------------------------------------- 1 | # Different variables / objects have different 2 | # data types - this is a central concept in the R programming language 3 | 4 | # Checking the Class of a Numeric Variable using class 5 | class(1) 6 | 7 | class(1.0) 8 | 9 | # Underlying data types are checked 10 | # with the typeof command - this is also called 11 | # storage level 12 | 13 | typeof(1) 14 | 15 | # Integer Variables are defined when we pass an L attached to the number 16 | # R stores numbers as "numeric" by default if we don't pass the L 17 | class(1L) 18 | 19 | # String variables 20 | class("test") 21 | 22 | # Logical Variables (or Boolean) 23 | class(TRUE) 24 | 25 | # We can test classes with is. : 26 | is.character("test") 27 | is.character(1) 28 | is.numeric(1) 29 | is.logical(TRUE) 30 | 31 | # Casting or Converting is also simple, let's start 32 | # by defining a string variable with the characters 10 33 | 34 | # Notice that this is not a numeric variable but a string 35 | # variable 36 | var <- "10" 37 | 38 | # This is one of the ways to convert variables into 39 | # arbitrary data types 40 | # Below, we convert var to numeric 41 | var_cast <- as(var,"numeric") 42 | 43 | class(var) 44 | class(var_cast) 45 | 46 | # We can also extend the as() family 47 | # to name the class that we want to convert to immediately: 48 | as.numeric("290") 49 | 50 | # Converting numerics to strings 51 | as.character(290) 52 | 53 | # We can also convert vector objects 54 | as.character(c(1,2,3,4,5)) 55 | 56 | # Another example, converting logical objects into numbers 57 | bool_vector <- c(TRUE,FALSE,FALSE,FALSE,TRUE) 58 | 59 | # This will output a vector of 0's and 1's 60 | as.numeric(bool_vector) 61 | 62 | 63 | -------------------------------------------------------------------------------- /10 - Reading External Data/01 - Loading external data (Excel-CSV).R: -------------------------------------------------------------------------------- 1 | # This script loads data from external sources 2 | # First we are going to load a CSV file 3 | 4 | # To work files, it's crucial to understand 5 | # the concept of working directories 6 | getwd() 7 | 8 | # You can use setwd to set a working directory 9 | # A relative path is built on top of your working directory 10 | # For the following path to work, the folder data that contains NYC temperature data.csv 11 | # must be on the folder that you see when you return getwd() function. 12 | nyc_temperature = read.csv("./data/NYC temperature data.csv") 13 | 14 | # An absolute path would take you the path independently 15 | # of your working directory, example: 16 | path = "C:\\Ivo\\Desktop\\data\\NYC temperature data.csv" 17 | 18 | # Absolute paths normally start on the root of your system 19 | 20 | # We can read other types of files, such as files in spreadsheet format 21 | # Install readxl package - you can skip this if you have 22 | # the package already installed in your environment 23 | install.packages("readxl") 24 | 25 | # load library 26 | library(readxl) 27 | 28 | # Read Excel data by providing the file relative path 29 | fbi_crime = read_excel("./data/FBI Crime Data.xls") 30 | 31 | # We can also use the library xlsx 32 | 33 | # Note: if you are having trouble using this new xlsx package 34 | # check this stack overflow thread 35 | # https://stackoverflow.com/questions/17376939/problems-when-trying-to-load-a-package-in-r-due-to-rjava 36 | 37 | # You may have to install java x64 and the library rJava to make it work 38 | # in some operating systems 39 | 40 | install.packages('xlsx') 41 | library('xlsx') 42 | crime_data_xlsx = read.xlsx("./data/FBI Crime Data.xls", 43 | header=TRUE, sheetName='16tbl01') 44 | 45 | # Typically, readxl is more used today -------------------------------------------------------------------------------- /9 - Working with Data Frames/04 - Apply Family.R: -------------------------------------------------------------------------------- 1 | # The apply family of functions are one of the most 2 | # common functions we can use in R 3 | 4 | # Although not only used in the context of dataframes, it 5 | # may be a bit easier to understand what they do in the 6 | # context of this object 7 | 8 | # Let's load the iris dataset, another famous example of 9 | # a toy dataset used throughout machine learning 10 | data(iris) 11 | 12 | ?iris 13 | 14 | # Apply applies something through an object depending on 15 | # a margin (2 equals to columns) 16 | 17 | # Below we are applying the mean for each column of 18 | # our dataset 19 | apply(iris, 2, mean) 20 | 21 | # Checking the documentation of the function 22 | ?apply 23 | 24 | # Unfortunately, apply is not convenient when we 25 | # apply certain functions. For example, applying mean 26 | # to dataframe columns when we have a character data type. 27 | 28 | # apply really depends on two things - the behavior 29 | # of the function we are applying and the 30 | # object we are applying a function to 31 | 32 | # As an example, we can apply max but we get in the return 33 | # a vector of characters, as the max function 34 | # can also be applied to strings 35 | apply(iris, 2, max) 36 | 37 | # Let's test mean applied to a numerical matrix 38 | our_matrix = matrix(data = c(1,2,3,4), nrow=2, ncol=2) 39 | 40 | apply(our_matrix, 2 ,mean) 41 | 42 | # We have alternative functions of the apply family, 43 | # such as lapply that returns a list - here we can 44 | # conveniently use a mean with lapply 45 | 46 | means <- lapply(iris, mean) 47 | 48 | # But this is not a silver bullet. 49 | # For example, sum yields an error when applied on a data frame 50 | # with characters - hence we may need to subset 51 | # the table in this case 52 | 53 | sum <- lapply(iris, sum) 54 | 55 | # Sapply is a wrapper of lapply and much prettier! 56 | sapply(iris[,1:4], min) 57 | 58 | # These functions can also apply custom functions 59 | # Bottom line, apply, sapply and lapply apply a function throughout 60 | # an object - they behavior depend on the type of function we are applying 61 | # and the object we are applying them to. 62 | 63 | -------------------------------------------------------------------------------- /11 - Functions/02 - Combining Functions and Data.R: -------------------------------------------------------------------------------- 1 | # Let's see how we can combine functions and using data frames 2 | # at the same time. 3 | 4 | # In this script, we have a very simple exercise of loading a dataset and 5 | # doing some visualizations using functions. 6 | 7 | # In your scripts, the libraries you are using should go on top: 8 | library(ggplot2) 9 | 10 | # Load the walmart_data and walmart_features files 11 | walmart_data = read.csv('./data/walmart_data.csv') 12 | walmart_features = read.csv('./data/walmart_features.csv') 13 | 14 | # We can really harness the power of functions to 15 | # plot any weekly sales by department and store 16 | 17 | sales_dept_store <- function(store, department) { 18 | # First, we need to subset by store and department 19 | filtered_table = ( 20 | walmart_data[(walmart_data$Store==store) & (walmart_data$Dept == department),] 21 | ) 22 | # Then, we can use our filtered table to plot the data 23 | # Here we're also using ggplot2 24 | ( 25 | ggplot(filtered_table, 26 | aes(x=as.Date(filtered_table$Date), y=filtered_table$Weekly_Sales, group=1)) 27 | + geom_line(color='orange') + geom_point(color='darkorange')+ 28 | theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) 29 | ) 30 | } 31 | 32 | # Let's call our custom sales_dept_store function for two different 33 | # stores 34 | sales_dept_store(20,3) 35 | sales_dept_store(10,3) 36 | 37 | # Let's add a color parameter to our function to extend its functionality: 38 | sales_dept_store <- function(store, department, color_plot) { 39 | # First, we need to subset 40 | filtered_table = ( 41 | walmart_data[(walmart_data$Store==store) & (walmart_data$Dept == department),] 42 | ) 43 | # Then, we can use our filtered table to plot the data 44 | ( 45 | ggplot(filtered_table, 46 | aes(x=as.Date(filtered_table$Date), y=filtered_table$Weekly_Sales, group=1)) 47 | + geom_line(color=color_plot) + geom_point(color=color_plot)+ 48 | theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) 49 | ) 50 | } 51 | 52 | sales_dept_store(20,3, 'blue') 53 | sales_dept_store(10,3, 'red') 54 | sales_dept_store(10,5, 'red') 55 | -------------------------------------------------------------------------------- /11 - Functions/01 - Functions Examples.R: -------------------------------------------------------------------------------- 1 | # Functions are one of the most important concepts 2 | # in the R programming language 3 | 4 | # R has its own built-in functions such as means: 5 | mean(c(10,20,30,40)) 6 | 7 | # But R enables us to develop our own custom functions 8 | # Let's first obtain the mean above using 9 | # a custom made function 10 | 11 | custom_mean <- function() { 12 | # Defining an example vector 13 | vector_example = c(10, 20, 30, 40) 14 | # Adding the values 15 | sum_value = sum(vector_example) 16 | # Computing the mean 17 | sum_value/length(vector_example) 18 | } 19 | 20 | # Calling our custom function that sequentially execute the three lines of code 21 | # we see wrapped in the function() definition. 22 | 23 | custom_mean() 24 | 25 | # It would be interesting if our mean would execute for different vectors. 26 | # Right now, we are hard-coding vector_example = c(10, 20, 30, 40) inside the function. 27 | # Let's change this to provide this vector example when calling the function: 28 | 29 | custom_mean <- function(vector_example) { 30 | # Adding the values 31 | sum_value = sum(vector_example) 32 | # Computing the mean 33 | sum_value/length(vector_example) 34 | } 35 | 36 | custom_mean(c(20, 30, 40, 50)) 37 | 38 | # The last instruction of the function is the one that is returned 39 | # from it. In this case, we are returning sum_value/length(vector_example) 40 | 41 | # We are still using a built-in R function -> sum() 42 | # We can also compute that function by ourselves 43 | # For loop example 44 | 45 | custom_mean_loop <- function(vector_example) { 46 | # First, we initialize sum_value as 0 47 | sum_value = 0 48 | # Our first example of an iterator: 49 | # We are passing through every element of the 50 | # vector_example passed in the input and incrementing 51 | # that value to the sum_value. 52 | 53 | for (i in vector_example) { 54 | sum_value = sum_value+i 55 | } 56 | # Computing the mean, using the accumulated sum_value 57 | sum_value/length(vector_example) 58 | } 59 | 60 | # Checking if our two functions match: 61 | custom_mean(c(20,30,40,50)) == custom_mean_loop(c(20,30,40,50)) 62 | 63 | # Let's see what happens inside this loop by printing the sum_value 64 | # at each iteration 65 | custom_mean_loop <- function(vector_example) { 66 | # Adding the values 67 | sum_value = 0 68 | for (i in vector_example) { 69 | sum_value = sum_value+i 70 | print(sum_value) 71 | } 72 | # Computing the mean 73 | sum_value/length(vector_example) 74 | } 75 | 76 | custom_mean_loop(c(20,30,40,50)) 77 | 78 | 79 | # Another way of controlling the control flow 80 | # of our function is to use if statements 81 | typeof(c('10','10')) 82 | 83 | custom_mean_loop <- function(vector_example) { 84 | if (typeof(vector_example)=="character") { 85 | print("Please provide a numeric vector!") 86 | } else { 87 | # Adding the values 88 | sum_value = 0 89 | for (i in vector_example) { 90 | sum_value = sum_value+i 91 | print(sum_value) 92 | } 93 | # Computing the mean 94 | sum_value/length(vector_example) 95 | } 96 | } 97 | 98 | # In functions, we have Implicit and Explicit returns 99 | # Implicit returns are what happens when your function 100 | # returns your last instruction 101 | 102 | # If you use explicit returns you have to use 103 | # return() inside your function 104 | 105 | 106 | -------------------------------------------------------------------------------- /2 - Vectors/01 - Vectors and Variable Assignment.R: -------------------------------------------------------------------------------- 1 | # Vectors 2 | # One of the most important object in R is the vector object 3 | 4 | # Let's define a vector using the c() function: 5 | c(1,2,3,4) 6 | 7 | # And assign it into an object that we can access later in the R Environment 8 | my_vec <- c(1,2,3,4) 9 | 10 | # Other way of assigning objects - Similar to what we have 11 | # seen above and for beginners has no practical difference 12 | my_vec = c(1,2,3,4) 13 | 14 | # Dividing my_vec by a number will return a new vector 15 | # with the original value divided by the number on the denominator 16 | my_vec/2 17 | 18 | # Adding two vectors element by element 19 | # Here we sum the vector with itself 20 | my_vec+my_vec 21 | 22 | # Sum operation is a function that we can 23 | # apply to this vector and returns a single number with 24 | # the sum of all values in the vector 25 | sum(my_vec) 26 | 27 | # We can also extract median and means from vectors 28 | median(my_vec) 29 | mean(my_vec) 30 | 31 | # Comparing elements using comparison elements will return a new vector 32 | # with TRUE / FALSE with the element tested against the condition. 33 | 34 | # Notice that equality is represented by two equal symbols (==) because 35 | # one single equal (=) represents assignment. 36 | my_vec < 2 37 | 38 | my_vec == 2 39 | 40 | # AND / OR Operators are also pretty common in the language. 41 | 42 | # AND operations 43 | my_vec == 2 & my_vec == 1 44 | 45 | # OR Operations 46 | my_vec == 2 | my_vec == 1 47 | 48 | # Let's now see some special cases that produce 49 | # special values in our objects and that need to be addressed 50 | 51 | # Division by Zero- this produce infinity Elements 52 | 1/0 53 | 54 | # Square root of negative numbers - produces NaN (short for Not a Number) 55 | sqrt(-1) 56 | 57 | # The effect on infinity and NaN on vector operations is pretty bad 58 | sum(c(1,2,3,1/0)) 59 | 60 | sum(c(1,2,3,sqrt(-1))) 61 | 62 | # Na's - Not Available - Pretty common in data analysis problems 63 | # This is a similar concept to NULL in databases 64 | ages <- c(15,16,NA,15) 65 | 66 | # Performing calculations on these elements 67 | # can be pretty frustrating 68 | mean(ages) 69 | 70 | # We can rely on the na.rm argument to help us 71 | # keep in mind that na.rm is only accessible for some functions! 72 | mean(ages, na.rm=TRUE) 73 | 74 | # It's important to know which objects are returned from 75 | # our calculations 76 | 77 | # This returns a single number: 78 | mean_ages <- mean(ages, na.rm=TRUE) 79 | 80 | # This returns a new vector: 81 | sorted_ages <- sort(ages) 82 | 83 | # Understanding that different operations return different elements 84 | # is very crucial to manipulate the R language. 85 | 86 | # An example of more mathematical calculations between vectors: 87 | 88 | vec1 <- c(1,2,3,4) 89 | vec2 <- c(1,2,3,4) 90 | 91 | vec1-vec2 92 | 93 | vec1+vec2 94 | 95 | vec1/vec2 96 | 97 | # When you call a function, if you don't provide the 98 | # name of the argument R will assume the order that you give. 99 | # The "inherent" order of the arguments that R is expecting 100 | # can be seen on help or by using ? 101 | 102 | help(mean) 103 | ?mean 104 | 105 | # mean takes x as first argument 106 | # if we don't name the x explicitly, the first argument will 107 | # be assumed as x, so doing: 108 | mean(vec1) 109 | 110 | # or this: 111 | mean(x=vec1) 112 | 113 | # returns exactly the same! 114 | 115 | # It's a good practice (particularly in custom functions) 116 | # to name your arguments - in R built-in function that's not 117 | # super meaningful because most developers know the arguments 118 | # they take 119 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # R Programming for Absolute Beginners 👨‍🎓👩‍🎓 2 | 3 | R is a programming language and software environment widely used for statistical computing and data analysis. R provides a wide variety of statistical and graphical techniques, including linear and nonlinear modeling, classical statistical tests, time-series analysis, clustering, and more. 4 | 5 | R is an open-source software, meaning that it is freely available for anyone to use and modify. It has become one of the most popular languages for data analysis and is used by researchers, analysts, and businesses around the world. Mostly, as it is a programming language tailored for data analysis, it works as an entry point for many non-coders into the data science and machine learning world. 6 | 7 | This repository is designed to help absolute beginners get started with R, covering all the essential topics such as R as a calculator, vectors, data types, arrays, matrices, data frames, lists, libraries, working with data frames, reading external files, and functions. 8 | 9 | **This repository is under license Creative Commons CC BY-SA. If you use any portion of it, please cite: *Bernardo, Ivo - R Programming: R Language For Absolute Beginners, 2022*** 10 | 11 | These materials are the base for my book *"R Programming: R Language for Absolute Beginners"* that you can buy on Amazon or Gumroad (in PDF format): 12 | 13 | - [Amazon](https://www.amazon.com/Programming-Language-Absolute-Beginners/dp/B0BQ94N9L7) 14 | - [GumRoad](https://ivopbernardo.gumroad.com/l/rlanguagebeginners) 15 | 16 | Additionally, you can find me explaining these materials (and more advanced stuff) on my [Udemy](https://www.udemy.com/course/r-for-absolute-beginners/?referralCode=F839A741D06F0200F312) course - currently a best seller on the platform. 17 | 18 | 19 | 20 | This is what we approach during the learning scripts: 21 | 22 | ## R as a Calculator 🖩 23 | These scripts will help you get familiar with R, by using it with it as a calculator! With R, you can perform all basic and complex arithmetic operations, while enjoying the flexibility and power of the programming language. Who needs a calculator when you have R? 24 | 25 | ## Vectors ➡️ 26 | The most basic R object and the first you should be familiar with. Vectors are similar to 1-dimensional arrays and you can use them to store and manipulate data of different types, and perform operations on them like a pro. This object is unidimensional and is able to hold a single data type at a time. 27 | 28 | ## Data Types 📊 29 | R offers a variety of data types, including integers, doubles, logical, and character. But wait, there's more! R also has some special data types, such as factors and dates, that can make your life easier when dealing with complex data sets. 30 | 31 | ## Arrays ♾️ 32 | Arrays are like vectors on steroids. They allow you to store data of multiple dimensions, and perform operations on them with ease. If you want to take your data manipulation skills to the next level, then you definitely need to learn about arrays in R and how you can work with multidimensional objects. 33 | 34 | ## Matrices 👩‍💻 35 | Matrices are very similar to arrays, but with their own constructor. You can use them to perform all sorts of matrix operations, like matrix multiplication, inversion, and eigenvalue decomposition. If you're into linear algebra, then matrices are your best friends! 36 | 37 | ## Data Frames 📙 38 | Data frames are a special type of data structure that allow you to store and manipulate data in a tabular format. You can think of them as an object similar to spreadsheets or tables. With data frames, you can easily import, manipulate, and export data from and to external sources. 39 | 40 | ## Lists 📜 41 | Lists are one of the most versatile data structures in R. They can store data of different types, including other lists, and can be nested to any level of depth. You can use them to represent complex data structures, and perform operations on them with ease. 42 | 43 | ## Libraries 📚 44 | R has a vast ecosystem of libraries that can help you perform all sorts of tasks, from data manipulation and visualization, to machine learning and statistics. You can think of libraries as pre-built toolboxes that can save you a lot of time and effort. 45 | 46 | ## Working with Data Frames 📙 47 | In this section, we'll dive deeper into data frames (the most important R object for data analysis), and learn how to perform some of the most common operations on them, such as filtering, sorting, grouping, and summarizing. We'll also learn how to visualize data frames using ggplot2, a popular data visualization library in R. 48 | 49 | ## Reading External Files 📂 50 | Often times, you'll need to import data from external sources, such as CSV files, Excel spreadsheets, or SQL databases. In this section, we'll learn how to read and write data from and to different file formats. 51 | 52 | ## Functions 🧩 53 | Functions are on of the building blocks of R programming. They allow you to encapsulate a piece of code into a reusable unit, and make your code more modular and organized. In this section, we'll learn how to define, call, and pass arguments to functions, and how to use some of the built-in functions in R. 54 | 55 | I hope you enjoy learning R programming and that this repository helps you get started on your journey. If you have any questions, feel free to contact me at ivopbernardo@gmail.com 56 | 57 | # Running the Materials 58 | 59 | To run the materials, you need to install R base on your computer. If you want, you can also use them inside an IDE (this is the prefered version). In the examples below, we are using R Studio. 60 | 61 | - [R Base Download](https://cran.r-project.org/bin/windows/base/) 62 | - [R Studio Download](https://posit.co/download/rstudio-desktop/) 63 | 64 | After installing both programs, navigate to a file in the course materials - here I'm exemplifying with the script in "1 - R as a Calculator\01 - Using R as a Calculator.R": 65 | 66 | ![Tutorial](assets/Tutorial1.PNG) 67 | 68 | Double clicking this file and this will launch a new R Studio window on your computer: 69 | 70 | ![Tutorial1](assets/Tutorial2.PNG) 71 | 72 | Select the piece of code you want to execute in the script window, for example `1 + 1` on the example below: 73 | 74 | ![Tutorial2](assets/Tutorial3.PNG) 75 | 76 | After selecting, you can run this code in two ways - either by using the Run button on the top right or by hitting `CTRL + Enter` (Windows) or `CMD + Enter` (Mac). After executing, you can see the result of your code in the command line window: 77 | 78 | ![Tutorial3](assets/Tutorial4.PNG) 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /10 - Reading External Data/data/NYC temperature data.csv: -------------------------------------------------------------------------------- 1 | date,actual_mean_temp,actual_min_temp,actual_max_temp,average_min_temp,average_max_temp,record_min_temp,record_max_temp,record_min_temp_year,record_max_temp_year,actual_precipitation,average_precipitation,record_precipitation 2 | 2014-7-1,81,72,89,68,83,52,100,1943,1901,0.00,0.12,2.17 3 | 2014-7-2,82,72,91,68,83,56,100,2001,1966,0.96,0.13,1.79 4 | 2014-7-3,78,69,87,68,83,54,103,1933,1966,1.78,0.12,2.80 5 | 2014-7-4,70,65,74,68,84,55,102,1986,1949,0.14,0.13,1.76 6 | 2014-7-5,72,63,81,68,84,53,101,1979,1999,0.00,0.12,3.07 7 | 2014-7-6,75,66,84,68,84,54,103,1979,2010,0.00,0.13,1.97 8 | 2014-7-7,81,72,90,68,84,56,100,1914,2010,0.04,0.13,3.13 9 | 2014-7-8,81,71,91,69,84,56,100,1894,1993,0.39,0.14,1.80 10 | 2014-7-9,80,71,88,69,84,54,106,1963,1936,0.09,0.14,1.09 11 | 2014-7-10,78,72,83,69,84,55,102,1890,1993,0.00,0.15,1.79 12 | 2014-7-11,79,71,86,69,84,57,98,1898,1988,0.00,0.15,1.94 13 | 2014-7-12,78,71,85,69,84,57,99,1926,1966,0.00,0.15,2.68 14 | 2014-7-13,78,72,83,69,84,54,101,1888,1966,0.03,0.17,3.16 15 | 2014-7-14,78,72,84,69,84,58,100,1926,1954,0.46,0.16,1.60 16 | 2014-7-15,79,72,86,69,84,57,102,1930,1995,1.30,0.15,2.33 17 | 2014-7-16,75,68,81,69,84,56,99,1946,1980,0.0,0.16,1.38 18 | 2014-7-17,74,67,81,69,84,57,100,1892,1953,0.00,0.15,3.13 19 | 2014-7-18,73,64,81,69,84,57,101,1925,1953,0.00,0.15,1.76 20 | 2014-7-19,72,68,76,69,84,57,102,1924,1977,0.00,0.16,1.82 21 | 2014-7-20,72,66,78,69,84,55,101,1890,1980,0.0,0.15,1.97 22 | 2014-7-21,76,67,85,69,84,55,104,1890,1977,0.00,0.15,2.26 23 | 2014-7-22,79,71,86,69,84,55,104,1873,2011,0.00,0.14,1.86 24 | 2014-7-23,80,72,88,69,84,58,100,1890,2011,0.19,0.15,2.41 25 | 2014-7-24,75,70,80,69,84,56,97,1893,1999,0.00,0.15,3.75 26 | 2014-7-25,74,66,82,69,84,57,97,1953,1999,0.00,0.15,1.64 27 | 2014-7-26,75,69,81,69,84,55,98,1920,1940,0.00,0.16,3.80 28 | 2014-7-27,78,71,85,69,84,55,98,1920,1963,0.02,0.16,2.65 29 | 2014-7-28,75,68,82,69,84,57,97,1903,1999,0.19,0.17,3.11 30 | 2014-7-29,70,64,76,69,84,59,99,1914,1949,0.00,0.17,3.47 31 | 2014-7-30,72,63,80,69,84,57,98,1956,1988,0.00,0.17,3.56 32 | 2014-7-31,75,68,82,69,84,57,102,1914,1933,0.00,0.17,2.29 33 | 2014-8-1,78,71,84,69,84,59,100,1964,1933,0.00,0.16,2.85 34 | 2014-8-2,69,63,74,69,84,58,100,1924,1955,0.41,0.16,2.49 35 | 2014-8-3,71,66,76,69,84,55,97,1927,2005,0.07,0.17,2.71 36 | 2014-8-4,77,70,84,69,84,56,100,1886,1944,0.00,0.16,3.25 37 | 2014-8-5,81,71,90,69,84,56,101,1951,1944,0.00,0.16,1.44 38 | 2014-8-6,77,70,83,69,84,57,97,1994,1955,0.00,0.16,3.31 39 | 2014-8-7,75,66,83,69,84,57,104,1994,1918,0.00,0.15,2.18 40 | 2014-8-8,74,65,83,69,84,54,99,1903,2001,0.00,0.15,2.60 41 | 2014-8-9,77,66,87,69,84,57,103,1989,2001,0.00,0.15,4.10 42 | 2014-8-10,78,68,88,69,83,55,98,1879,1949,0.00,0.14,4.64 43 | 2014-8-11,79,71,87,69,83,56,102,1962,1944,0.00,0.14,2.39 44 | 2014-8-12,75,70,79,68,83,55,97,1889,1944,0.19,0.14,3.62 45 | 2014-8-13,75,68,82,68,83,55,99,1930,2005,0.53,0.14,2.70 46 | 2014-8-14,70,63,77,68,83,54,99,1964,1988,0.00,0.15,5.81 47 | 2014-8-15,67,61,73,68,83,54,97,1964,1988,0.00,0.14,1.52 48 | 2014-8-16,71,63,78,68,83,55,96,1880,1944,0.00,0.15,4.80 49 | 2014-8-17,74,66,82,68,83,56,95,1979,1944,0.01,0.14,2.86 50 | 2014-8-18,72,63,81,68,83,55,94,1915,2002,0.00,0.14,3.95 51 | 2014-8-19,73,63,83,68,83,55,94,1924,2002,0.00,0.15,2.53 52 | 2014-8-20,77,70,84,68,82,55,97,1949,1955,0.00,0.14,3.63 53 | 2014-8-21,74,65,83,68,82,53,96,1922,1955,0.35,0.15,4.19 54 | 2014-8-22,72,65,79,67,82,52,95,1895,1916,0.06,0.14,1.85 55 | 2014-8-23,72,67,77,67,82,51,92,1923,1916,0.01,0.14,3.03 56 | 2014-8-24,72,64,80,67,82,52,94,1890,1972,0.00,0.14,3.61 57 | 2014-8-25,76,64,88,67,82,52,95,1940,1948,0.00,0.14,1.86 58 | 2014-8-26,80,70,89,67,81,53,103,1887,1948,0.00,0.12,3.24 59 | 2014-8-27,80,70,90,67,81,50,101,1885,1948,0.00,0.13,4.16 60 | 2014-8-28,74,66,82,66,81,50,100,1885,1948,0.00,0.13,3.99 61 | 2014-8-29,71,61,80,66,81,50,99,1986,1953,0.00,0.12,2.68 62 | 2014-8-30,73,65,80,66,81,50,98,1965,1973,0.00,0.12,2.30 63 | 2014-8-31,82,73,90,66,80,50,100,1976,1953,0.62,0.12,3.76 64 | 2014-9-1,82,75,88,66,80,51,97,1872,1953,0.00,0.13,3.84 65 | 2014-9-2,85,77,92,65,80,51,102,1886,1953,0.00,0.13,2.12 66 | 2014-9-3,79,72,86,65,80,50,99,1893,1929,0.00,0.13,3.32 67 | 2014-9-4,78,69,87,65,79,47,97,1883,1929,0.00,0.14,3.48 68 | 2014-9-5,80,72,87,64,79,51,94,1963,1985,0.00,0.13,2.45 69 | 2014-9-6,79,67,91,64,79,48,97,1924,1881,0.11,0.13,3.26 70 | 2014-9-7,73,65,81,64,78,46,101,1888,1881,0.00,0.14,2.07 71 | 2014-9-8,70,65,75,64,78,54,93,1955,1919,0.00,0.13,4.86 72 | 2014-9-9,68,63,73,63,78,48,94,1883,1915,0.00,0.13,0.86 73 | 2014-9-10,72,63,80,63,77,43,97,1883,1983,0.00,0.13,1.38 74 | 2014-9-11,76,69,83,63,77,43,99,1917,1983,0.00,0.13,2.90 75 | 2014-9-12,70,62,78,62,77,46,94,1917,1961,0.00,0.14,2.35 76 | 2014-9-13,64,58,69,62,76,46,94,1963,1952,0.26,0.14,3.94 77 | 2014-9-14,62,53,71,62,76,46,93,1975,1931,0.00,0.14,3.82 78 | 2014-9-15,63,55,71,61,76,45,92,1913,1927,0.00,0.15,4.16 79 | 2014-9-16,64,58,70,61,75,47,93,1966,1915,0.37,0.15,5.02 80 | 2014-9-17,64,55,73,61,75,45,93,1986,1991,0.00,0.15,3.37 81 | 2014-9-18,67,57,76,60,75,44,91,1990,1891,0.00,0.15,3.92 82 | 2014-9-19,60,54,66,60,74,44,94,1929,1983,0.00,0.15,4.30 83 | 2014-9-20,66,57,75,59,74,44,93,1993,1983,0.00,0.15,2.32 84 | 2014-9-21,71,67,75,59,73,40,95,1871,1895,0.15,0.15,5.54 85 | 2014-9-22,63,55,71,59,73,41,95,1904,1914,0.0,0.15,2.34 86 | 2014-9-23,62,52,71,58,73,41,97,1947,1895,0.00,0.14,8.28 87 | 2014-9-24,65,58,71,58,72,40,89,1963,1959,0.00,0.15,2.26 88 | 2014-9-25,61,57,64,57,72,40,90,1887,1970,0.32,0.14,2.36 89 | 2014-9-26,68,58,77,57,71,42,91,1940,1970,0.00,0.15,2.34 90 | 2014-9-27,72,60,83,57,71,41,90,1957,1933,0.00,0.15,3.13 91 | 2014-9-28,74,64,84,56,70,41,88,1947,1881,0.00,0.16,3.84 92 | 2014-9-29,73,67,79,56,70,42,88,1942,1945,0.00,0.16,2.18 93 | 2014-9-30,67,62,71,55,70,39,89,1912,1986,0.0,0.16,2.64 94 | 2014-10-1,63,61,65,55,69,36,88,1947,1927,0.02,0.15,4.98 95 | 2014-10-2,66,61,70,55,69,39,90,1886,1927,0.00,0.14,2.16 96 | 2014-10-3,64,56,71,54,68,38,87,1974,1919,0.00,0.14,1.55 97 | 2014-10-4,61,52,69,54,68,37,88,1888,1941,1.18,0.13,4.05 98 | 2014-10-5,54,46,61,54,68,35,94,1881,1941,0.00,0.15,1.99 99 | 2014-10-6,60,50,69,53,67,36,90,1881,1941,0.00,0.14,2.39 100 | 2014-10-7,67,63,71,53,67,39,88,1999,1944,0.06,0.15,4.09 101 | 2014-10-8,68,62,73,52,67,37,87,1988,2007,0.04,0.14,4.30 102 | 2014-10-9,62,55,68,52,66,37,86,2000,1916,0.00,0.15,7.33 103 | 2014-10-10,58,52,64,52,66,35,91,1888,1939,0.0,0.16,2.16 104 | 2014-10-11,55,50,60,51,65,34,85,1964,1949,0.33,0.15,3.06 105 | 2014-10-12,56,48,63,51,65,35,86,1876,1954,0.00,0.14,4.26 106 | 2014-10-13,59,52,65,51,65,33,87,1875,1954,0.05,0.14,2.75 107 | 2014-10-14,70,63,76,50,64,37,84,1988,1920,0.00,0.15,1.76 108 | 2014-10-15,73,69,77,50,64,32,84,1876,1956,0.69,0.14,1.70 109 | 2014-10-16,66,61,71,50,64,34,87,1876,1897,1.11,0.14,2.15 110 | 2014-10-17,65,59,71,50,63,33,90,1886,1938,0.00,0.14,2.28 111 | 2014-10-18,63,56,70,49,63,35,82,1974,1928,0.00,0.14,2.45 112 | 2014-10-19,50,44,56,49,63,30,83,1940,1963,0.00,0.14,4.35 113 | 2014-10-20,51,42,60,49,62,31,80,1974,1969,0.00,0.14,2.78 114 | 2014-10-21,61,55,67,48,62,32,84,1974,1920,0.11,0.14,2.17 115 | 2014-10-22,54,50,58,48,62,30,88,1940,1979,1.51,0.15,1.51 116 | 2014-10-23,52,50,53,48,61,32,85,1969,1947,0.61,0.14,2.97 117 | 2014-10-24,57,51,63,48,61,31,79,1969,2001,0.00,0.14,2.51 118 | 2014-10-25,59,50,67,47,61,29,79,1879,1963,0.01,0.15,3.30 119 | 2014-10-26,58,53,63,47,61,30,78,1879,1964,0.0,0.13,3.40 120 | 2014-10-27,56,48,63,47,60,28,82,1936,1963,0.00,0.14,1.88 121 | 2014-10-28,63,53,72,47,60,29,83,1976,1919,0.00,0.13,2.49 122 | 2014-10-29,62,51,72,46,60,31,78,1925,1971,0.0,0.14,3.67 123 | 2014-10-30,53,47,59,46,59,31,82,1925,1961,0.00,0.13,1.64 124 | 2014-10-31,50,45,55,46,59,29,81,1925,1946,0.05,0.14,2.41 125 | 2014-11-1,45,42,47,46,59,30,84,1885,1950,0.35,0.14,1.69 126 | 2014-11-2,45,41,48,45,58,30,83,1887,1950,0.00,0.14,1.70 127 | 2014-11-3,50,39,61,45,58,28,79,1875,2003,0.00,0.13,2.60 128 | 2014-11-4,61,53,68,45,58,25,78,1879,1975,0.00,0.13,1.44 129 | 2014-11-5,60,56,64,45,57,23,78,1879,1961,0.00,0.13,1.94 130 | 2014-11-6,53,48,57,44,57,27,74,1879,1948,0.37,0.14,1.47 131 | 2014-11-7,47,40,53,44,57,29,78,1930,1938,0.00,0.13,2.96 132 | 2014-11-8,42,36,48,44,57,29,76,1886,1975,0.00,0.12,7.40 133 | 2014-11-9,52,46,57,44,56,24,75,1976,1975,0.00,0.13,3.65 134 | 2014-11-10,53,44,61,43,56,27,73,1914,1985,0.00,0.13,1.70 135 | 2014-11-11,57,49,64,43,56,28,74,1933,1949,0.00,0.12,1.41 136 | 2014-11-12,56,47,65,43,55,26,76,1926,1879,0.00,0.12,2.39 137 | 2014-11-13,42,36,48,43,55,22,73,1873,1931,0.20,0.13,2.06 138 | 2014-11-14,39,35,42,42,55,20,72,1905,1993,0.06,0.13,2.23 139 | 2014-11-15,38,33,42,42,54,20,80,1967,1993,0.00,0.13,2.43 140 | 2014-11-16,40,35,45,42,54,17,72,1933,1928,0.03,0.13,2.39 141 | 2014-11-17,46,40,52,41,53,19,71,1933,1953,1.54,0.14,1.54 142 | 2014-11-18,35,24,45,41,53,18,73,1936,1928,0.00,0.14,1.24 143 | 2014-11-19,29,22,36,41,53,18,72,1936,1921,0.00,0.14,1.95 144 | 2014-11-20,38,31,45,40,52,20,77,1873,1985,0.00,0.13,3.37 145 | 2014-11-21,33,28,37,40,52,16,74,1879,1900,0.00,0.14,1.33 146 | 2014-11-22,36,28,44,40,52,13,72,1880,1931,0.00,0.14,2.03 147 | 2014-11-23,50,43,57,40,51,14,72,1880,1931,0.00,0.14,1.84 148 | 2014-11-24,61,53,69,39,51,14,73,1880,1979,0.70,0.14,1.95 149 | 2014-11-25,60,51,68,39,50,19,73,1938,1979,0.00,0.13,1.36 150 | 2014-11-26,43,34,51,39,50,16,67,1938,1946,1.24,0.14,1.91 151 | 2014-11-27,36,34,38,38,50,12,72,1932,1896,0.02,0.13,2.15 152 | 2014-11-28,33,29,37,38,49,15,70,1930,2011,0.00,0.14,2.14 153 | 2014-11-29,36,27,45,38,49,15,69,1872,1990,0.00,0.14,2.01 154 | 2014-11-30,50,45,55,37,49,7,70,1875,1991,0.00,0.15,1.11 155 | 2014-12-1,54,42,65,37,48,9,70,1875,2006,0.09,0.14,1.72 156 | 2014-12-2,39,35,43,37,48,12,66,1875,1970,0.08,0.14,2.16 157 | 2014-12-3,44,41,46,36,47,9,69,1976,1998,0.06,0.15,1.63 158 | 2014-12-4,41,37,45,36,47,10,74,1882,1998,0.00,0.14,1.84 159 | 2014-12-5,39,34,44,35,47,11,70,1926,2001,0.51,0.14,1.28 160 | 2014-12-6,45,39,50,35,46,11,71,1871,2001,1.22,0.13,1.60 161 | 2014-12-7,36,30,42,35,46,10,75,1926,1998,0.04,0.14,1.98 162 | 2014-12-8,31,24,37,34,45,10,65,1882,1927,0.00,0.14,1.54 163 | 2014-12-9,39,36,42,34,45,7,66,1876,1966,2.54,0.13,2.54 164 | 2014-12-10,36,32,40,34,45,3,70,1876,1946,0.08,0.14,1.62 165 | 2014-12-11,35,31,38,33,44,6,64,1880,1879,0.01,0.14,2.41 166 | 2014-12-12,35,32,38,33,44,5,68,1988,1931,0.00,0.13,1.60 167 | 2014-12-13,39,34,44,33,44,8,64,1960,1923,0.00,0.13,3.03 168 | 2014-12-14,42,38,46,32,43,12,67,1976,1881,0.00,0.13,2.22 169 | 2014-12-15,43,37,48,32,43,6,67,1874,2008,0.00,0.13,1.34 170 | 2014-12-16,44,38,49,32,43,7,63,1876,1971,0.20,0.12,2.25 171 | 2014-12-17,48,42,54,32,42,1,62,1919,2000,0.02,0.13,2.28 172 | 2014-12-18,40,37,42,31,42,-1,63,1919,1984,0.00,0.12,1.30 173 | 2014-12-19,35,31,38,31,42,-1,58,1884,1931,0.00,0.12,1.58 174 | 2014-12-20,32,30,33,31,42,-4,60,1942,2002,0.00,0.12,1.82 175 | 2014-12-21,34,31,36,30,41,-1,65,1942,2013,0.0,0.13,2.49 176 | 2014-12-22,40,35,44,30,41,2,71,1872,2013,0.04,0.12,2.18 177 | 2014-12-23,45,43,46,30,41,-1,66,1883,1990,0.16,0.13,1.61 178 | 2014-12-24,51,44,58,30,41,6,63,1983,1996,0.80,0.13,1.42 179 | 2014-12-25,53,44,62,29,40,-1,64,1980,1982,0.09,0.13,1.30 180 | 2014-12-26,45,40,50,29,40,3,63,1914,1982,0.00,0.12,1.66 181 | 2014-12-27,50,44,55,29,40,6,63,1872,1949,0.00,0.12,2.14 182 | 2014-12-28,49,43,54,29,40,8,65,1917,1982,0.10,0.12,1.35 183 | 2014-12-29,39,34,44,28,39,-6,70,1917,1984,0.00,0.11,2.52 184 | 2014-12-30,31,28,34,28,39,-13,65,1917,1984,0.00,0.12,1.69 185 | 2014-12-31,30,27,32,28,39,-7,63,1917,1965,0.00,0.11,2.31 186 | 2015-1-1,33,27,39,28,39,-4,62,1918,1966,0.00,0.12,2.05 187 | 2015-1-2,39,35,42,28,39,2,68,1918,1876,0.00,0.12,1.92 188 | 2015-1-3,38,33,42,28,39,-4,64,1879,2000,0.71,0.12,2.42 189 | 2015-1-4,49,41,56,27,39,-3,66,1918,1950,0.30,0.12,2.73 190 | 2015-1-5,35,21,49,27,38,-4,64,1904,1993,0.00,0.12,1.50 191 | 2015-1-6,21,19,22,27,38,-2,72,1896,2007,0.05,0.13,1.65 192 | 2015-1-7,16,9,23,27,38,4,64,2014,1907,0.00,0.12,2.67 193 | 2015-1-8,15,8,21,27,38,2,65,1968,1998,0.00,0.11,1.25 194 | 2015-1-9,26,19,33,27,38,-1,64,1968,1937,0.07,0.13,1.42 195 | 2015-1-10,20,16,23,27,38,-6,60,1875,1876,0.00,0.12,1.72 196 | 2015-1-11,28,18,37,27,38,3,63,1968,1975,0.00,0.12,1.46 197 | 2015-1-12,37,35,39,27,38,2,64,1981,1890,0.36,0.13,2.35 198 | 2015-1-13,27,17,36,27,38,-3,68,1914,1932,0.00,0.12,1.44 199 | 2015-1-14,24,16,32,27,38,-5,70,1914,1932,0.00,0.12,2.06 200 | 2015-1-15,30,25,35,27,38,0,67,1957,1932,0.00,0.13,1.27 201 | 2015-1-16,32,20,43,27,38,1,58,2004,1995,0.00,0.12,1.44 202 | 2015-1-17,25,17,32,27,38,-2,63,1977,1990,0.00,0.12,1.36 203 | 2015-1-18,37,31,42,27,38,0,66,1982,1990,2.10,0.11,2.10 204 | 2015-1-19,39,36,42,27,38,-3,64,1875,1951,0.00,0.12,2.39 205 | 2015-1-20,36,32,40,27,38,0,61,1994,2006,0.00,0.11,1.41 206 | 2015-1-21,31,25,36,27,38,-2,63,1985,2006,0.00,0.12,3.45 207 | 2015-1-22,36,31,40,27,38,0,61,1888,1959,0.00,0.12,1.70 208 | 2015-1-23,34,28,39,27,38,-3,62,1936,1906,0.00,0.11,2.55 209 | 2015-1-24,36,33,39,27,38,-6,68,1882,1967,0.72,0.11,2.18 210 | 2015-1-25,37,31,42,27,38,2,60,1945,1967,0.00,0.11,1.80 211 | 2015-1-26,27,22,31,27,39,3,72,1927,1950,0.48,0.11,2.19 212 | 2015-1-27,25,20,30,27,39,-1,69,1927,1916,0.36,0.11,1.94 213 | 2015-1-28,25,16,34,27,39,-2,66,1925,1916,0.00,0.11,1.87 214 | 2015-1-29,28,19,36,27,39,0,69,1873,2002,0.02,0.11,1.03 215 | 2015-1-30,29,19,38,27,39,2,64,1873,2006,0.06,0.11,1.19 216 | 2015-1-31,20,13,26,27,39,-1,63,1920,1947,0.00,0.12,1.51 217 | 2015-2-1,28,20,36,27,39,-2,67,1920,1989,0.03,0.11,2.12 218 | 2015-2-2,24,14,34,27,39,-3,59,1881,1988,1.02,0.11,2.98 219 | 2015-2-3,20,13,26,27,39,0,64,1955,1991,0.00,0.11,1.55 220 | 2015-2-4,34,24,43,28,40,0,68,1918,1991,0.00,0.10,2.10 221 | 2015-2-5,28,14,42,28,40,-6,70,1918,1991,0.00,0.11,1.43 222 | 2015-2-6,20,12,27,28,40,-4,68,1895,2008,0.00,0.11,2.74 223 | 2015-2-7,33,25,40,28,40,1,54,1910,1938,0.02,0.11,2.96 224 | 2015-2-8,33,29,37,28,40,-7,61,1934,1965,0.00,0.11,1.15 225 | 2015-2-9,27,25,29,28,40,-15,63,1934,1990,0.09,0.10,1.74 226 | 2015-2-10,33,26,40,28,41,-6,61,1899,2001,0.01,0.11,2.63 227 | 2015-2-11,28,22,34,28,41,-2,65,1899,1960,0.00,0.10,2.74 228 | 2015-2-12,28,16,40,28,41,-3,62,1914,1999,0.0,0.11,1.66 229 | 2015-2-13,15,8,21,29,41,-1,64,1914,1951,0.00,0.10,2.42 230 | 2015-2-14,24,16,32,29,41,2,63,1916,1946,0.02,0.11,1.59 231 | 2015-2-15,15,4,25,29,42,-8,73,1943,1949,0.0,0.10,1.73 232 | 2015-2-16,12,3,21,29,42,1,71,1888,1954,0.00,0.12,1.40 233 | 2015-2-17,21,14,27,29,42,-5,67,1896,1976,0.14,0.11,1.49 234 | 2015-2-18,26,19,33,29,42,0,68,1979,1981,0.0,0.11,1.50 235 | 2015-2-19,18,8,27,30,42,1,66,1936,1997,0.00,0.11,2.15 236 | 2015-2-20,11,2,19,30,43,2,69,2015,1939,0.00,0.11,3.07 237 | 2015-2-21,23,13,32,30,43,4,68,1896,1930,0.61,0.11,1.86 238 | 2015-2-22,38,32,43,30,43,8,69,1963,1997,0.10,0.11,2.39 239 | 2015-2-23,23,8,38,30,43,5,70,1889,1985,0.00,0.12,1.38 240 | 2015-2-24,14,4,24,30,44,-4,75,1873,1985,0.00,0.12,1.69 241 | 2015-2-25,29,20,37,31,44,1,75,1914,1930,0.00,0.11,2.11 242 | 2015-2-26,27,21,32,31,44,7,65,1990,1890,0.00,0.12,1.87 243 | 2015-2-27,24,18,30,31,44,5,72,1900,1997,0.00,0.12,1.56 244 | 2015-2-28,21,13,29,31,45,5,67,1934,1976,0.00,0.12,1.21 245 | 2015-3-1,28,24,31,31,45,5,73,1884,1972,0.52,0.13,2.95 246 | 2015-3-2,33,27,39,32,45,9,72,1891,1972,0.00,0.12,2.41 247 | 2015-3-3,30,22,37,32,45,11,65,2003,1991,0.67,0.12,2.25 248 | 2015-3-4,40,35,45,32,46,7,70,1943,1974,0.25,0.13,1.65 249 | 2015-3-5,30,19,40,32,46,3,72,1872,1880,0.76,0.13,1.81 250 | 2015-3-6,20,12,27,32,46,6,68,1872,1935,0.00,0.13,2.63 251 | 2015-3-7,28,18,38,33,47,7,74,1890,1946,0.00,0.13,1.87 252 | 2015-3-8,43,37,49,33,47,8,76,1883,1987,0.00,0.14,1.78 253 | 2015-3-9,47,40,54,33,47,11,69,1996,2000,0.01,0.13,1.82 254 | 2015-3-10,46,39,53,33,48,12,74,1929,2006,0.46,0.13,1.62 255 | 2015-3-11,52,44,59,34,48,14,73,1960,1977,0.01,0.13,2.94 256 | 2015-3-12,42,36,47,34,48,8,71,1888,1890,0.00,0.13,2.33 257 | 2015-3-13,37,31,43,34,49,6,85,1888,1990,0.00,0.12,3.86 258 | 2015-3-14,46,40,51,35,49,15,75,1896,1946,0.81,0.14,1.02 259 | 2015-3-15,40,36,44,35,49,14,77,1993,1990,0.00,0.14,1.81 260 | 2015-3-16,44,35,52,35,50,13,82,1911,1990,0.00,0.14,2.03 261 | 2015-3-17,46,34,57,35,50,9,75,1916,1945,0.02,0.15,1.42 262 | 2015-3-18,34,29,39,36,50,7,77,1916,1989,0.00,0.14,3.10 263 | 2015-3-19,36,29,43,36,51,8,76,1967,1918,0.00,0.15,2.19 264 | 2015-3-20,34,29,38,36,51,11,83,1885,1945,0.40,0.15,1.93 265 | 2015-3-21,38,29,47,37,51,10,84,1885,1921,0.0,0.15,2.37 266 | 2015-3-22,36,28,43,37,52,12,78,1885,2012,0.00,0.15,3.44 267 | 2015-3-23,31,23,38,37,52,12,76,1875,1923,0.00,0.16,1.60 268 | 2015-3-24,36,26,45,37,52,12,76,1888,1988,0.00,0.15,2.05 269 | 2015-3-25,42,34,49,38,53,13,79,1878,1963,0.05,0.15,4.25 270 | 2015-3-26,52,42,62,38,53,20,76,1960,1922,0.32,0.15,1.42 271 | 2015-3-27,43,39,46,38,54,20,83,1894,1998,0.27,0.16,1.79 272 | 2015-3-28,33,26,40,39,54,13,84,1923,1945,0.0,0.15,2.98 273 | 2015-3-29,36,25,46,39,54,10,86,1923,1945,0.00,0.15,2.03 274 | 2015-3-30,45,36,54,39,55,16,82,1887,1998,0.0,0.16,2.45 275 | 2015-3-31,41,35,47,40,55,14,86,1923,1998,0.17,0.15,2.20 276 | 2015-4-1,42,32,51,40,56,12,83,1923,1917,0.00,0.16,1.89 277 | 2015-4-2,54,41,67,40,56,22,81,1919,1967,0.00,0.16,1.93 278 | 2015-4-3,62,59,64,41,56,24,81,1954,1981,0.04,0.16,1.90 279 | 2015-4-4,51,42,60,41,57,21,80,1874,1892,0.01,0.16,1.99 280 | 2015-4-5,52,42,61,41,57,20,80,1874,1928,0.00,0.16,2.76 281 | 2015-4-6,53,42,63,42,58,21,79,1982,1947,0.00,0.15,2.52 282 | 2015-4-7,52,42,62,42,58,21,92,1982,2010,0.15,0.16,1.35 283 | 2015-4-8,41,37,45,42,58,25,90,1982,1991,0.00,0.15,1.93 284 | 2015-4-9,40,37,43,43,59,25,86,1977,1991,0.00,0.16,3.42 285 | 2015-4-10,48,39,56,43,59,28,86,1997,1922,0.17,0.17,4.31 286 | 2015-4-11,51,44,57,43,60,24,84,1909,1955,0.00,0.16,1.10 287 | 2015-4-12,55,43,66,44,60,22,90,1874,1977,0.00,0.16,2.12 288 | 2015-4-13,59,50,68,44,60,25,88,1874,1977,0.00,0.16,1.26 289 | 2015-4-14,60,55,65,44,61,26,85,1950,1941,0.01,0.16,2.72 290 | 2015-4-15,62,51,72,45,61,28,87,1943,1941,0.00,0.15,7.57 291 | 2015-4-16,58,52,64,45,62,29,92,1928,2002,0.00,0.14,3.29 292 | 2015-4-17,63,55,71,45,62,28,96,1875,2002,0.08,0.15,1.29 293 | 2015-4-18,70,59,80,46,62,25,96,1875,1976,0.00,0.14,2.19 294 | 2015-4-19,56,48,64,46,63,21,92,1875,1976,0.00,0.15,1.96 295 | 2015-4-20,52,46,57,46,63,24,90,1897,1927,1.37,0.14,1.96 296 | 2015-4-21,59,52,65,47,63,26,87,1875,1923,0.20,0.14,2.28 297 | 2015-4-22,59,48,69,47,64,33,86,1947,2001,0.05,0.14,2.45 298 | 2015-4-23,47,41,52,47,64,32,86,1930,2007,0.00,0.14,2.34 299 | 2015-4-24,46,39,52,48,64,31,87,1930,2001,0.00,0.14,2.17 300 | 2015-4-25,50,38,62,48,65,29,91,1919,1915,0.00,0.14,1.68 301 | 2015-4-26,55,46,64,48,65,31,92,1919,2009,0.00,0.14,1.88 302 | 2015-4-27,56,49,62,48,65,36,92,1932,1915,0.00,0.14,2.04 303 | 2015-4-28,61,50,71,49,66,34,90,1934,1990,0.00,0.15,2.74 304 | 2015-4-29,64,50,78,49,66,32,89,1874,1974,0.00,0.14,0.91 305 | 2015-4-30,58,48,67,49,66,30,91,1875,1942,0.00,0.13,4.97 306 | 2015-5-1,56,49,63,50,67,35,87,1880,2001,0.00,0.12,2.48 307 | 2015-5-2,61,48,74,50,67,37,90,1903,2001,0.00,0.12,1.10 308 | 2015-5-3,66,51,80,50,67,36,90,1874,2001,0.00,0.13,1.66 309 | 2015-5-4,71,57,85,50,68,38,92,1917,2001,0.00,0.13,2.02 310 | 2015-5-5,76,66,85,51,68,34,90,1891,1980,0.00,0.13,1.55 311 | 2015-5-6,66,59,73,51,68,32,92,1891,1986,0.0,0.13,1.46 312 | 2015-5-7,68,56,80,51,68,37,93,1891,2000,0.00,0.14,3.82 313 | 2015-5-8,69,56,82,52,69,37,91,1947,2000,0.00,0.12,3.02 314 | 2015-5-9,64,57,70,52,69,35,94,1947,1979,0.00,0.13,1.42 315 | 2015-5-10,72,61,83,52,69,36,94,1966,1979,0.00,0.13,2.10 316 | 2015-5-11,77,70,84,52,70,36,92,1913,1993,0.0,0.12,1.67 317 | 2015-5-12,75,64,86,53,70,40,93,1907,1881,0.00,0.13,1.84 318 | 2015-5-13,62,53,70,53,70,39,89,1895,1956,0.00,0.12,1.66 319 | 2015-5-14,62,50,73,53,70,40,88,1878,1900,0.00,0.12,3.38 320 | 2015-5-15,65,55,75,54,71,42,90,1947,1900,0.00,0.13,1.16 321 | 2015-5-16,66,57,75,54,71,42,90,1878,1951,0.30,0.13,2.66 322 | 2015-5-17,74,64,83,54,71,39,92,1956,1974,0.02,0.13,1.05 323 | 2015-5-18,68,60,75,55,71,41,90,1973,1936,0.00,0.13,2.18 324 | 2015-5-19,70,59,80,55,72,38,99,1976,1962,0.0,0.13,2.02 325 | 2015-5-20,61,54,67,55,72,43,96,2002,1996,0.00,0.14,2.03 326 | 2015-5-21,57,52,62,55,72,40,93,1907,1996,0.00,0.14,1.94 327 | 2015-5-22,65,55,74,56,72,44,96,1990,1941,0.00,0.15,1.25 328 | 2015-5-23,60,49,70,56,73,43,94,1963,1964,0.00,0.15,2.70 329 | 2015-5-24,69,56,81,56,73,39,93,1963,1975,0.00,0.15,2.07 330 | 2015-5-25,75,64,85,57,73,41,95,1925,1880,0.00,0.15,0.86 331 | 2015-5-26,78,67,88,57,74,42,95,1967,1880,0.00,0.15,1.28 332 | 2015-5-27,78,70,85,57,74,41,96,1961,1880,0.08,0.14,2.62 333 | 2015-5-28,78,70,85,58,74,43,94,1961,1959,0.00,0.14,1.16 334 | 2015-5-29,75,65,85,58,74,43,97,1902,1969,0.00,0.16,3.99 335 | 2015-5-30,76,67,85,58,75,42,97,1884,1987,0.00,0.15,2.19 336 | 2015-5-31,72,57,87,59,75,46,96,1938,1939,1.46,0.15,3.13 337 | 2015-6-1,55,51,58,59,75,44,96,1945,1895,0.72,0.16,2.60 338 | 2015-6-2,53,50,55,59,76,48,96,1946,1895,0.37,0.16,2.79 339 | 2015-6-3,61,52,70,60,76,45,95,1929,1895,0.00,0.16,3.01 340 | 2015-6-4,60,54,65,60,76,48,99,1926,1925,0.00,0.16,2.75 341 | 2015-6-5,63,55,70,60,76,47,99,1945,1925,0.13,0.16,2.80 342 | 2015-6-6,68,60,76,61,77,47,98,1945,1925,0.19,0.16,2.62 343 | 2015-6-7,65,55,74,61,77,47,96,1897,1925,0.00,0.16,4.16 344 | 2015-6-8,71,63,79,61,77,47,95,1932,1933,0.06,0.16,1.47 345 | 2015-6-9,76,68,83,62,78,47,97,1980,1933,0.01,0.16,2.55 346 | 2015-6-10,74,65,82,62,78,49,96,1972,2008,0.00,0.16,2.07 347 | 2015-6-11,81,72,89,62,78,46,95,1972,1973,0.00,0.16,1.14 348 | 2015-6-12,81,73,88,63,78,48,93,1979,1973,0.00,0.16,2.18 349 | 2015-6-13,79,72,86,63,79,51,96,1953,1961,0.00,0.16,1.71 350 | 2015-6-14,77,66,88,63,79,49,99,1875,1956,0.36,0.16,2.54 351 | 2015-6-15,74,64,83,64,79,48,96,1933,1994,0.57,0.15,1.13 352 | 2015-6-16,72,65,79,64,80,52,97,1927,1891,0.27,0.15,1.31 353 | 2015-6-17,74,66,82,64,80,51,96,1926,1957,0.0,0.16,1.82 354 | 2015-6-18,68,64,71,65,80,48,95,1950,1929,0.00,0.14,2.30 355 | 2015-6-19,78,68,87,65,80,52,98,1920,1994,0.00,0.14,2.16 356 | 2015-6-20,70,64,75,65,81,49,98,1914,1923,0.0,0.13,1.39 357 | 2015-6-21,80,71,88,65,81,49,97,1897,1988,0.64,0.14,1.70 358 | 2015-6-22,79,70,87,66,81,52,98,1940,1988,0.00,0.13,1.96 359 | 2015-6-23,83,75,90,66,81,49,96,1918,1888,0.02,0.13,1.75 360 | 2015-6-24,76,68,84,66,82,52,96,1932,1888,0.00,0.13,1.46 361 | 2015-6-25,74,65,83,66,82,50,99,1873,1952,0.00,0.14,1.28 362 | 2015-6-26,75,69,81,67,82,56,100,1979,1952,0.00,0.13,4.29 363 | 2015-6-27,65,58,71,67,82,55,101,1940,1966,1.12,0.12,2.11 364 | 2015-6-28,68,62,73,67,83,54,96,1995,1991,0.29,0.13,1.69 365 | 2015-6-29,70,63,76,67,83,52,101,1919,1934,0.00,0.12,2.57 366 | 2015-6-30,75,68,82,67,83,53,99,1919,1964,0.00,0.13,3.07 367 | --------------------------------------------------------------------------------