19/6/2012 (C) PentaLibra 20121 Writing R for Dummies London R user group June 2012 Andrie de Vries...

Preview:

Citation preview

(C) PentaLibra 201219/6/2012 1

Writing R for Dummies

London R user group

June 2012

Andrie de Vries

andrie@pentalibra.com

(C) PentaLibra 2012 2

How to write a book?

19/6/2012

(C) PentaLibra 2012

Four easy steps

19/6/2012 (#)

Write Edit Review Publish

(C) PentaLibra 2012 (#)

The authors

• Andrie de Vries

• Director, PentaLibra

• Market researcher

• Uses R for surveys and survey statistics

• Joris Meys

• University of Ghent, Belgium

• Statistician

• Teaches R to PhD students

19/6/2012

(C) PentaLibra 2012 5

Why us?

19/6/2012

(C) PentaLibra 201219/6/2012 6

(C) PentaLibra 2012 7

Who is the book for?

19/6/2012

(C) PentaLibra 2012

Who is the book for?

19/6/2012 (#)

Statisticians?

Programmers?

SPSS users?

Excel users?

(C) PentaLibra 2012

Who is the book for?

19/6/2012 (#)

Target reader has no experience of programming or statistics

(C) PentaLibra 2012 10

How to decide what to cover?

19/6/2012

(C) PentaLibra 2012 1119/6/2012

- -.Date -.POSIXt ! !.hexmode !.octmode != $ $.DLLInfo $.package_version $<- $<-.data.frame %% %*% %/% %in% %o% %x% & && &.hexmode &.octmode ( * *.difftime .__H__.cbind .__H__.rbind .amatch_bounds .amatch_costs .C .cache_class .Call .Call.graphics .colMeans .colSums .decode_numeric_version .Defunct .deparseOpts .Deprecated .difftime .doTrace .dynLibs .encode_numeric_version .expand_R_libs_env_var .Export .External .External.graphics .find.package .First.sys .Fortran .getRequiredPackages .getRequiredPackages2 .gt .gtn .handleSimpleError .Import .ImportFrom .Internal .isMethodsDispatchOn .isOpen .kronecker .libPaths .make_numeric_version .makeMessage .mergeExportMethods .mergeImportMethods .NotYetImplemented .NotYetUsed .OptRequireMethods .packages .packageStartupMessage .path.package .POSIXct .POSIXlt .Primitive .primTrace .primUntrace .readRDS .row_names_info .rowMeans .rowSums .S3method .saveRDS .Script .set_row_names .signalSimpleWarning .standard_regexps .subset .subset2 .TAOCP1997init / /.difftime : :: ::: @ [ [.AsIs [.data.frame [.Date [.difftime [.factor [.hexmode [.listof [.noquote [.numeric_version [.octmode [.POSIXct [.POSIXlt [.simple.list [[ [[.data.frame [[.Date [[.factor [[.numeric_version [[.POSIXct [[<- [[<-.data.frame [[<-.factor [[<-.numeric_version [<- [<-.data.frame [<-.Date [<-.factor [<-.POSIXct [<-.POSIXlt ^ { | |.hexmode |.octmode || ~ + +.Date +.POSIXt < <- <<- <= = == > >= abbreviate abs acos acosh addNA addTaskCallback agrep alist all all.equal all.equal.character all.equal.default all.equal.factor all.equal.formula all.equal.language all.equal.list all.equal.numeric all.equal.POSIXct all.equal.raw all.names all.vars any anyDuplicated anyDuplicated.array anyDuplicated.data.frame anyDuplicated.default anyDuplicated.matrix aperm aperm.default aperm.table append apply Arg args array arrayInd as.array as.array.default as.call as.character as.character.condition as.character.Date as.character.default as.character.error as.character.factor as.character.hexmode as.character.numeric_version as.character.octmode as.character.POSIXt as.character.srcref as.complex as.data.frame as.data.frame.array as.data.frame.AsIs as.data.frame.character as.data.frame.complex as.data.frame.data.frame as.data.frame.Date as.data.frame.default as.data.frame.difftime as.data.frame.factor as.data.frame.integer as.data.frame.list as.data.frame.logical as.data.frame.matrix as.data.frame.model.matrix as.data.frame.numeric as.data.frame.numeric_version as.data.frame.ordered as.data.frame.POSIXct as.data.frame.POSIXlt as.data.frame.raw as.data.frame.table as.data.frame.ts as.data.frame.vector as.Date as.Date.character as.Date.date as.Date.dates as.Date.default as.Date.factor as.Date.numeric as.Date.POSIXct as.Date.POSIXlt as.difftime as.double as.double.difftime as.double.POSIXlt as.environment as.expression as.expression.default as.factor as.function as.function.default as.hexmode as.integer as.list as.list.data.frame as.list.Date as.list.default as.list.environment as.list.factor as.list.function as.list.numeric_version as.list.POSIXct as.logical as.logical.factor as.matrix as.matrix.data.frame as.matrix.default as.matrix.noquote as.matrix.POSIXlt as.name as.null as.null.default as.numeric as.numeric_version as.octmode as.ordered as.package_version as.pairlist as.POSIXct as.POSIXct.date as.POSIXct.Date as.POSIXct.dates as.POSIXct.default as.POSIXct.numeric as.POSIXct.POSIXlt as.POSIXlt as.POSIXlt.character as.POSIXlt.date as.POSIXlt.Date as.POSIXlt.dates as.POSIXlt.default as.POSIXlt.factor as.POSIXlt.numeric as.POSIXlt.POSIXct as.qr as.raw as.real as.single as.single.default as.symbol as.table as.table.default as.vector as.vector.factor asin asinh

(C) PentaLibra 2012

Each Dummies

book:

19/6/2012 (#)

(C) PentaLibra 2012 13

So what’s in the book?

19/6/2012

(C) PentaLibra 2012

What exactly are we saying here?(Copyright Rich Tennant)19/6/2012 (#)

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 15

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?• Chapter 1: Introducing R: The Big Picture

• Chapter 2: Exploring R

• Chapter 3: The Fundamentals of R

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 16

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?• Chapter 1: Introducing R: The Big Picture

• Chapter 2: Exploring R

• Chapter 3: The Fundamentals of R

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 17

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?• Chapter 1: Introducing R: The Big Picture

• Chapter 2: Exploring R

• Chapter 3: The Fundamentals of R

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 18

(C) PentaLibra 201219/6/2012 19

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R• Chapter 4: Getting Started with Arithmetic

• Chapter 5: Getting Started with Reading and Writing

• Chapter 6: Going on a Date with R

• Chapter 7: Working in More Dimensions

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 20

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R• Chapter 4: Getting Started with Arithmetic

• Chapter 5: Getting Started with Reading and Writing

• Chapter 6: Going on a Date with R

• Chapter 7: Working in More Dimensions

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 21

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R• Chapter 4: Getting Started with Arithmetic

• Chapter 5: Getting Started with Reading and Writing

• Chapter 6: Going on a Date with R

• Chapter 7: Working in More Dimensions

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 22

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R• Chapter 4: Getting Started with Arithmetic

• Chapter 5: Getting Started with Reading and Writing

• Chapter 6: Going on a Date with R

• Chapter 7: Working in More Dimensions

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 23

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R• Chapter 8: Putting the Fun in Functions

• Chapter 9: Controlling the Logical Flow

• Chapter 10: Debugging Your Code

• Chapter 11: Getting Help

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 24

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R• Chapter 8: Putting the Fun in Functions

• Chapter 9: Controlling the Logical Flow

• Chapter 10: Debugging Your Code

• Chapter 11: Getting Help

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 25

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R• Chapter 8: Putting the Fun in Functions

• Chapter 9: Controlling the Logical Flow

• Chapter 10: Debugging Your Code

• Chapter 11: Getting Help

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 26

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R• Chapter 8: Putting the Fun in Functions

• Chapter 9: Controlling the Logical Flow

• Chapter 10: Debugging Your Code

• Chapter 11: Getting Help

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 27

(C) PentaLibra 2012

Writer’s block

19/6/2012 (#)

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk• Chapter 12: Getting Data into and out of R

• Chapter 13: Manipulating and Processing Data

• Chapter 14: Summarizing Data

• Chapter 15: Testing Differences and Relations

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 29

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk• Chapter 12: Getting Data into and out of R

• Chapter 13: Manipulating and Processing Data

• Chapter 14: Summarizing Data

• Chapter 15: Testing Differences and Relations

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 30

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk• Chapter 12: Getting Data into and out of R

• Chapter 13: Manipulating and Processing Data

• Chapter 14: Summarizing Data

• Chapter 15: Testing Differences and Relations

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 31

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk• Chapter 12: Getting Data into and out of R

• Chapter 13: Manipulating and Processing Data

• Chapter 14: Summarizing Data

• Chapter 15: Testing Differences and Relations

■ Part V: Working with Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 32

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics• Chapter 16: Using Base Graphics

• Chapter 17: Creating Faceted Graphics with Lattice

• Chapter 18: Looking At ggplot2 Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 33

(C) PentaLibra 201219/6/2012 34

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics• Chapter 16: Using Base Graphics

• Chapter 17: Creating Faceted Graphics with Lattice

• Chapter 18: Looking At ggplot2 Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 35

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics• Chapter 16: Using Base Graphics

• Chapter 17: Creating Faceted Graphics with Lattice

• Chapter 18: Looking At ggplot2 Graphics

■ Part VI: The Part of Tens

Table of contents

19/6/2012 36

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens• Chapter 19: Ten Things You Can Do in

R That You Would've Done in Microsoft Excel

• Chapter 20: Ten Tips on Working with Packages

Table of contents

19/6/2012 37

(C) PentaLibra 2012

■ Introduction

■ Part I: R You Ready?

■ Part II: Getting Down to Work in R

■ Part III: Coding in R

■ Part IV: Making the Data Talk

■ Part V: Working with Graphics

■ Part VI: The Part of Tens• Chapter 19: Ten Things You Can Do in R

That You Would've Done in Microsoft Excel

• Chapter 20: Ten Tips on Working with Packages

Table of contents

19/6/2012 38

(C) PentaLibra 201219/6/2012 39

(C) PentaLibra 2012 (#)

• Web:• www.pentalibra.com

• Twitter:• @pentalibra

• #rfordummies

• Email:• andrie@pentalibra.com

19/6/2012