Introduction to R. Why use R Its FREE!!! And powerful, fairly widely used, lots of online posts about it Uses S -> an object oriented programing language.

Slides:



Advertisements
Similar presentations
R for Macroecology Aarhus University, Spring 2011.
Advertisements

Introduction to arrays
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
EGN 1006 – Introduction to Engineering Engineering Problem Solving and Excel.
Chapter 4 Systems of Linear Equations; Matrices
Chapter 4 Systems of Linear Equations; Matrices
Lesson 14 Creating Formulas and Charting Data
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
Basics of Using R Xiao He 1. AGENDA 1.What is R? 2.Basic operations 3.Different types of data objects 4.Importing data 5.Basic data manipulation 2.
Maths for Computer Graphics
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Introduction to MATLAB
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
Matlab Intro. Outline Matlab introduction Matlab elements Types Variables Matrices.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Introduction to R: The Basics Rosales de Veliz L., David S.L., McElhiney D., Price E., & Brooks G. Contributions from Ragan. M., Terzi. F., & Smith. E.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week2: Data Structure, Types and Manipulation in R.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
732A44 Programming in R.  Self-studies of the course book  2 Lectures (1 in the beginning, 1 in the end)  Labs (computer). Compulsory submission of.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
13.1 Matrices and Their Sums
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction to MATLAB. CSPP58001 MATLAB MATLAB is is a matrix-based language well suited for carrying out numerical analysis. It has many, many high-
STAT 251 Lab 1. Outline Lab Accounts Introduction to R.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
4.5 Inverse of a Square Matrix
Operations with Matrices: Multiplication
STAT 534: Statistical Computing Hari Narayanan
Learning Objectives for Section 4.5 Inverse of a Square Matrix
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
PROGRAMMING IN R Introduction to R. In this session I will: Introduce you to the R program and windows Show how to install R Write basic programs in R.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
R objects  All R entities exist as objects  They can all be operated on as data  We will cover:  Vectors  Factors  Lists  Data frames  Tables 
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Introduction to R Chris Free. Introduction to R Free! Superior (if not comparable) to commercial alternatives Available on all platforms Not just for.
Review > x[-c(1,4,6)] > Y[1:3,2:8] > island.data fishData$weight[1] > fishData[fishData$weight < 20 & fishData$condition.
Introduction to R.
ECE 1304 Introduction to Electrical and Computer Engineering
13.4 Product of Two Matrices
Programming in R Intro, data and programming structures
Introduction to R Carolina Salge March 29, 2017.
Welcome to the course! Meetings and communication: AC meetings
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Communication and Coding Theory Lab(CS491)
Introduction to Matlab
R Course 1st Lecture.
Introduction to Matlab
Matlab Training Session 2: Matrix Operations and Relational Operators
Data analysis with R and the tidyverse
Introduction to Matlab:
Matrices and Determinants
Presentation transcript:

Introduction to R

Why use R Its FREE!!! And powerful, fairly widely used, lots of online posts about it Uses S -> an object oriented programing language which allows one to create objects with ‘proerpties’, ‘methods’, and ‘classes’ Community based development and debugging

Documentation and Installation Official R website: – – FAQs are very useful – Has mailing lists focusing on various aspects of R Help, development, packages Installation: – Choose precompiled binary for your operating system – PC: best to install it under c:\R\ versus c:\Program Files\R\ R studio, makes it easier to interact with R: –

Let the fun begin! Double click on the R icon Opens up a ‘command window’ The > sign is the prompt, which indicates you are ready to enter commands Now we must learn how to ‘talk’ to R so that it understands us

Objects R operates on entities that are technically known as objects that correspond to specfic classes and methods for the storage of information, for example: – vectors (class “numeric”): vectors contains successions of elements of the same nature: numeric (real number), complex, logical (True, False) or character) – matrices (class “matrix”): matrices are successions of column vectors that all contain elements of the same nature – dataframe (class “data.frame”): dataframes are also successions of column vectors but unlike vectors and matrices they may contain vectors of different natures. A character vector (for example gender) can thus border a numeric vector (for example the age) – lists (class “list”): lists are ordered sequences of objects which can be of any mode: the first object of the list may be a vector, the second a matrix and the third another list.

Functions Functions are also objects, everything’s an object!! Format: – Functionname(argument1, argument2,…..) – Arguments can be of any class

Useful functions Basic functions: >c(x,y,z) # create a vector of the elements x, y and z in paranthesis. >cbind(x,y,z)# create a matrix with the vectors x, y and z. >length(x)# indicate the length of a vector or a list x >sum(x)# calculate the sum of the elements of the vector or matrix x. >colMeans(x)# calculate the mean of the elements of the vector or matrix x. >max(x);min(x)# indicate the highest or smallest value of the vector or matrix x. >summary(x)# provides generic summary information for an object Functions for finding out info about objects >ls()# indicate the name of all the objects available in the environment of R. >dimnames(x)# indicate the name of the rows and columns of.a matrix or a dataframe x. >dimnames(x)[[1]]# indicate the name of the rows of.a matrix or a dataframe x. >dimnames(x)[[2]]# indicate the name of the columns of.a matrix or a dataframe x. >class(x)# list the type of an object Misc useful functions: >help(x)# open the help of R about the function (or other objects) x >barplot(x)# display the barplot of the elements of the vector x >as.matrix(x)# change the class of a dataframe x to class “matrix”. Often useful as the operations available for objects of class “data.frame” and “matrix” differ. >as.data.frame(x)# change the class of a matrix x to class “data.frame” >q()# quit R >rm(x)# delete the object x of the environment of R. >x11()# open an empty graphical window.

Mathematical operations +addition /division -substraction ^power *multiplication sqrt ()square root

Assignment Assignment is an operation that permits to assign to an object of any class an other object of any class. The function that allows this action is the function assign() but its shortcuts “=” and “<-” are often preferred.

Examples

Exercise 1 Imagine you wanted to evaluate the function below for the following pairs: (3,2), (6,4), (9,6), (12,8), (15,10) Very time consuming by hand, but can use our new found friend, R! >x<-c(3,6,9,12,15) # create the vector x. >y<-c(2,4,6,8,10) # create the vector y. > f.xy<-sqrt((3*x^2+2*y)/((x+y)*(x-y))) To analyse the results, you could also have created a matrix that would have contained the results vector f.xy and the vectors x and y: >Results<-cbind(x,y,f.xy)

Accessing elements of an object Use coordinates of the desired information in the object via square barckets “[ ]”. if x is a vector: name.vector[coordinate] if x is a matrix: name.matrix[row.coordinate,column.coordinate] if x is a data.frame: name.dataframe[row.coordinate,column.coordinate] if x is a list: name.list[[coordinate]] Vectors: a[c(2,3)] or a[2:3] # the second and the third elements of the vector >f.xy[3] # the third elements of the vector f.xy. >y[ ] # the entire vector f.xy.

Accessing lists and matrices Lists: A<-dimnames(Results) # A contains a list of the row and column names of the matrix Results. >A[[2]] # the second element of A contains the column’s names of Results. >A[[2]][3] # the third column’s name of Results. Matrices: >M1[1,3] # first row, third column >M1[1:2,2:3] #first two rows of the 2 nd and 3 rd columns Results[3,1] # third element of the first column of Results. >Results[,1] # entire first column of Results >Results[2,] # entire second row of Results. >Results[-2,-2] # Results without its second row and its second column. Results[c(1,2),"f.xy"] # first and second element of the column vector called "f.xy”, can use column names

Exercise 2 Read in dataset: – hs0 <- read.table(" header=T, sep=",") 1.List the first 20 rows for all columns 2.What type of object is hs0? How can you verify this? 3.Create a new object called scores with just the first 20 observations of read, write, math, science scores 4.Display dimensions of new object 5.Display length of just math scores 6.Get basic statistics for scores 7.Find the mean of science scores – Doesn’t work!! Need to exclude NA’s (na.rm=T) 8.Go back to full dataset, find the mean of write and math scores for each program type