1 / 22

Introduction to

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

mala
Download Presentation

Introduction to

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 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. • 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 • Add 10 + 20 • Multiply 10 * 20 • Divide 10 / 20 • Raise to a power 10 ** 20 • Modulo 10 %/% 20 • Integer division 10 %% 4

  10. Vectors • 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

  11. Simple Operations on Vectors • 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

  12. Combining Vectors

  13. 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)

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

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

  16. 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”)

  17. 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”)

  18. 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”

  19. Getting Help (Again) • Html search engine

More Related