Difference between revisions of "R"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 10: Line 10:
 
'''Note:''' Each numbered topic corresponds to a single spoken tutorial. Each bulleted point corresponds to a command or topic that must be covered in the given spoken tutorial.
 
'''Note:''' Each numbered topic corresponds to a single spoken tutorial. Each bulleted point corresponds to a command or topic that must be covered in the given spoken tutorial.
  
==Module 1: Introduction to basics of R ==
+
== Introduction to basics of R ==
  
 
* Version of '''R''' and '''RStudio''' used
 
* Version of '''R''' and '''RStudio''' used
Line 39: Line 39:
  
  
==Module 2: Introduction to data frames in R==
+
== Introduction to data frames in R==
  
 
* Storing captaincy information in '''vectors'''
 
* Storing captaincy information in '''vectors'''
Line 60: Line 60:
  
  
==Module 3: Introduction to RStudio==
+
== Introduction to RStudio==
  
 
* Features of '''RStudio'''  
 
* Features of '''RStudio'''  
Line 80: Line 80:
  
  
==Module 4: Introduction to R script==
+
== Introduction to R script==
  
 
* What is an '''R''' script
 
* What is an '''R''' script
Line 103: Line 103:
  
  
==Module 5: Working Directories in RStudio==
+
== Working Directories in RStudio==
  
 
* What is working directory in '''R'''
 
* What is working directory in '''R'''
Line 126: Line 126:
  
  
==Module 6: Indexing and Slicing Data Frames==
+
== Indexing and Slicing Data Frames==
  
 
* Shortcut key for assignment operator (<code><-</code>)
 
* Shortcut key for assignment operator (<code><-</code>)
Line 149: Line 149:
 
   
 
   
  
==Module 7: Creating Matrices using Data Frames==
+
== Creating Matrices using Data Frames==
  
 
* Data required in a matrix format
 
* Data required in a matrix format
Line 170: Line 170:
  
  
==Module 8: Operations on Matrices and Data Frames==
+
== Operations on Matrices and Data Frames==
  
 
* How to find the inverse of a matrix  
 
* How to find the inverse of a matrix  
Line 189: Line 189:
  
  
==Module 9: Merging and Importing Data==
+
== Merging and Importing Data==
  
 
*Use of built-in functions in '''R''' for exploring a data frame
 
*Use of built-in functions in '''R''' for exploring a data frame
Line 206: Line 206:
  
  
==Module 10: Data Types and Factors==
+
== Data Types and Factors==
  
 
* What is an object in '''R'''
 
* What is an object in '''R'''
Line 229: Line 229:
  
  
==Module 11: Lists and its Operations==
+
== Lists and its Operations==
  
 
* Lists in '''R'''  
 
* Lists in '''R'''  
Line 252: Line 252:
  
  
==Module 12: Plotting Histograms and Pie Chart==
+
== Plotting Histograms and Pie Chart==
  
 
* How to find the dimensions of a data frame  
 
* How to find the dimensions of a data frame  
Line 275: Line 275:
  
  
==Module 13: Plotting Bar Charts and Scatter Plot==  
+
== Plotting Bar Charts and Scatter Plot==  
  
 
* What is a bar chart
 
* What is a bar chart
Line 298: Line 298:
  
  
==Module 14: Introduction to ggplot2==  
+
== Introduction to ggplot2==  
  
 
* Define visualization
 
* Define visualization
Line 321: Line 321:
  
  
==Module 15: Aesthetic Mapping in ggplot2==  
+
== Aesthetic Mapping in ggplot2==  
  
 
* Define aesthetic  
 
* Define aesthetic  

Revision as of 17:05, 2 August 2019

R ( http://www.r-project.org/) is an open source software - a well organized and sophisticated package - that facilitates data analysis, modeling, inferential testing and forecasting. It is a user friendly software which allows to create new function commands to solve statistical problems. It runs on a variety of UNIX platforms (and similar systems such as LINUX), Windows and Mac OS.

R is the most preferred open source language for analytics and data science. At Microsoft, R is used by its data scientists, who apply machine learning to data from Bing, Azure, Office, and the Sales, Marketing, and Finance departments. Twitter has been using R for measuring user-experience. On the other hand, the cross-platform compatibility of R and its capacity to handle large and complex data sets make it an ideal tool for academicians to analyze data in their labs.

R can be used for simple calculations, matrix calculations, differential equations, optimisation, statistical analysis, plotting graphs, etc. Also, it is useful to anybody who wishes to undertake extensive statistical computations and data visualization.


Note: Each numbered topic corresponds to a single spoken tutorial. Each bulleted point corresponds to a command or topic that must be covered in the given spoken tutorial.

Introduction to basics of R

  • Version of R and RStudio used
  • Operating systems on which these run
  • Quick intro to R and RStudio
  • Resizing the font and window size
  • Using +, -, ^, sqrt
  • Using exp, log, sin
  • Different ways of invoking log
  • Vectors using seq and length
  • Using pi
  • Plotting a sine function
  • Defining more points to get a smooth plot
  • Plotting with points and as line
  • Introduction to help


Introduction to data frames in R

  • Storing captaincy information in vectors
  • Constructing a data frame using vectors
  • Plotting one vector of a data frame vs. another one
  • Adding a vector to a data frame
  • Saving a data frame into a csv file
  • Preventing the writing of row numbers into the csv file
  • Changing the contents of a csv file through a text editor
  • Loading a csv file into a data frame
  • Accessing the data sets that come with R


Introduction to RStudio

  • Features of RStudio
  • A look at the windows in RStudio interface:
    • Source and Console windows
    • Workspace window
    • Plots and Files window
  • Example to plot a simple data set
  • Introduction to packages in R
  • How to find the list of packages installed in R
  • Installation of R packages in RStudio
  • Loading and using R packages


Introduction to R script

  • What is an R script
  • Features of R script
  • How to create and save an R script from the user interface (UI) of RStudio
  • Shortcut keys to create an R script
  • How to use auto-completion of commands
  • How to run an entire script
  • How to run a block of a script
  • How to add comments
  • How to comment an existing line
  • How to load one script into another script


Working Directories in RStudio

  • What is working directory in R
  • How to know current working directory
  • How to use getwd function
  • How to set a working directory from the user interface of RStudio
  • How to set a working directory from the Console window of RStudio
  • How to use setwd function
  • How to read and store a csv file in R
  • How to use read.csv function
  • How to view a stored csv file in R
  • How to use View function


Indexing and Slicing Data Frames

  • Shortcut key for assignment operator (<-)
  • How to perform numeric indexing
  • How to extract a row or column from a data frame
  • How to retrieve multiple rows from a data frame
  • How to combine objects to form a vector
  • How to perform logical indexing on a data frame
  • How to perform name indexing on a data frame
  • How to slice a data frame using subset function
  • How to select required columns (by name) from a data frame
  • How to retrieve data using double square brackets


Creating Matrices using Data Frames

  • Data required in a matrix format
  • Convert a data frame into a matrix
  • Create a matrix with known data
  • Add two matrices
  • Subtract two matrices
  • Multiply two matrices element wise
  • Perform true matrix multiplication
  • Calculate the transpose of a matrix
  • Calculate the determinant of a matrix


Operations on Matrices and Data Frames

  • How to find the inverse of a matrix
  • How to calculate the sum of elements in a matrix using for loop
  • How to calculate the sum of elements in a matrix using sum function
  • How to calculate time elapsed in an operation
  • How to find out the sum of rows of a matrix
  • How to find out the sum of columns of a matrix
  • How to add a new column or row to an existing data-frame
  • How to use cbind and rbind function


Merging and Importing Data

  • Use of built-in functions in R for exploring a data frame
  • Access help in RStudio
  • Advantages of merging data frames
  • Merge two data frames
  • Import data from command line
  • Import xml file and txt file in R
  • Import data from user interface of RStudio


Data Types and Factors

  • What is an object in R
  • Types of R - objects
  • What is an atomic vector in R
  • Types of atomic vectors
  • How to find types of vectors
  • Factors in R
  • Levels of a factor in R
  • Identification of categorical variables
  • How to change the type of a vector
  • How to change the values of levels


Lists and its Operations

  • Lists in R
  • Atomic vectors in R
  • Difference between atomic vectors and lists in R
  • How to create a list
  • How to assign names to the elements of a list
  • Named list in R
  • How to access elements of a list by its index
  • How to access an element of a list by its name
  • How to access an element of an element of a list
  • Combine two different lists


Plotting Histograms and Pie Chart

  • How to find the dimensions of a data frame
  • Define a histogram
  • Plot a histogram in R
  • Add labels to the histogram
  • Add color to the bins of a histogram
  • Change the number of breaks in the histogram
  • Define a pie chart
  • Plotting a pie chart in R
  • Add a label to the pie chart
  • Saving the plot as an image


Plotting Bar Charts and Scatter Plot

  • What is a bar chart
  • Draw a bar chart
  • Use the barplot function
  • Add labels to the bar chart
  • Adjust the labels of the bar chart
  • What is a scatter plot
  • Draw a scatter plot
  • Use plot function with two objects
  • Find the correlation coefficient
  • Range of correlation coefficient


Introduction to ggplot2

  • Define visualization
  • About grammar of graphics - ggplot2
  • Use of the plot function
  • Add labels to a plot
  • Change the color and type of plot
  • Plot two graphs in the same plot
  • Add a legend to the plot
  • About ggplot2 package
  • Draw a scatter plot using ggplot function
  • Save plots using ggsave function


Aesthetic Mapping in ggplot2

  • Define aesthetic
  • Need for aesthetic in plotting
  • Draw a scatter plot
  • Customize a scatter plot
  • View the structure of an object
  • View the levels of a categorical variable
  • Draw a bar chart using ggplot
  • Add labels to a plot in ggplot
  • Use the fill argument in aesthetic mapping
  • Draw a histogram using ggplot

Contributors and Content Editors

Manivel, Nancyvarkey, Sudhakarst