Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.

Similar presentations


Presentation on theme: "Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming."— Presentation transcript:

1 Introduction to GTECH 201 Session 13

2 What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming language

3 Getting Started Starting R

4 Getting Help Getting help > help ( ) provides help on how to use ‘help’ > help (topic) provides help on a specific topic > help.start ( ) brings you to a web interface to the R documentation

5 R functions take arguments (information that you put into the function which goes between the brackets) and can perform a range of tasks. In the case of the ‘help’ function the task is to display information from the R documentation files. R Functions help ( ) is an R function

6 R as Calculator R will evaluate basic calculations which you type into the console (input window)

7 Assigning Values With the <- operator With a regular = equal sign

8 R as Calculator In the previous example x and y are variables. We obtained the sum of x and y by typing x + y In the same way we could carry out much more complicated calculations Generally you can obtain the number (or other value) stored in any letter by typing the letter followed by enter (or by typing print (letter) or show (letter))

9 Simple Operations Add10 + 20 Multiply10 * 20 Divide10 / 20 Raise to a power10 ** 20 Modulo10 %/% 20 Integer division10 % 4

10 In R you can think of vectors as being equivalent to a single column of numbers. You can create a vector using the c( ) function as follows: x <- c( ) e.g. x <- c(1,2,4,8) creates a column of the numbers 1,2,4,8 Vectors

11 When you carry out simple operations (+ - * /) on vectors in R that have the same number of entries R just performs the normal operations on the numbers in the vector entry by entry If the vectors don’t have the same number of entries then R will cycle through the vector with the smaller number of entries Vectors can be assigned by putting together other vectors Simple Operations on Vectors

12

13

14

15 Combining Vectors

16 Matrices and Lists Matrix Rectangular table of data of the same type Arrays are 3-, 4-,.. n-dimensional matrices List An ordered collection of data of arbitrary types > doe = list(name="john",age=28,married=F)

17 Data Frames The tables we know from Excel Each column has the same type But different columns may be of different type

18 Subsetting Individual elements of a vector, matrix, array or data frame are accessed with “[ ]” by specifying their index, or their name

19 Storing Data Every R object can be stored into and restored from a file with the commands “save” and “load” > save(x, file=“x.Rdata”) > load(“x.Rdata”)

20 R Import and Export Most programs (e.g. Excel) know how to deal with rectangular tables in the form of tab-delimited text files > x = read.delim(“filename.txt”) also: read.table, read.csv > write.table(x, file=“x.txt”, sep=“\t”)

21 Importing Data Caveats Type conversions The read functions try to guess and autoconvert the data types of the different columns (e.g. number, factor, character) Special characters Delimiter character (space, comma, tabulator) cannot be part of a data field To circumvent this, text may be “quoted”

22 Getting Help (Again) Html search engine


Download ppt "Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming."

Similar presentations


Ads by Google