+ All Categories
Home > Documents > R basics workshop

R basics workshop

Date post: 22-Feb-2016
Category:
Upload: tareq
View: 23 times
Download: 0 times
Share this document with a friend
Description:
R basics workshop. J. Sebasti án Tello Iván Jiménez. Center for Conservation and Sustainable Development Missouri Botanical Garden. 3 fundamental concepts:. Function Argument Object. 2 . Functions and Arguments. Writing in R is like writing in English. Jump three times forward. - PowerPoint PPT Presentation
Popular Tags:
20
R basics workshop J. Sebastián Tello Iván Jiménez Center for Conservation and Sustainable Development Missouri Botanical Garden
Transcript
Page 1: R basics workshop

R basics workshopJ. Sebastián TelloIván JiménezCenter for Conservation and Sustainable DevelopmentMissouri Botanical Garden

Page 2: R basics workshop

3 fundamental concepts:

• Function

• Argument

• Object

Page 3: R basics workshop

2. Functions and Arguments

Page 4: R basics workshop

Writing in R is like writing in English

Jump three times forward

Action Modifiers

Page 5: R basics workshop

Generate a sequence from 5 to 20 with values spaced by 0.5

Action Modifiers

Writing in R is like writing in English

Page 6: R basics workshop

seq(from=5, to=20, by=0.5)

Action Modifiers

Function Arguments

Generate a sequence from 5 to 20 with values spaced by 0.5

Writing in R is like writing in English

Page 7: R basics workshop

seq(from = 5, to = 20, by = 0.5)

Basic anatomy of an R command

Function

Open parenthesis

Argumentname

Equal sign

Other arguments

CommaClose

parenthesis

Argumentvalue

Page 8: R basics workshop

• A function in R defines an action to take, and is similar to a verb in English

• Functions apply to arguments, which define on what and how a function will work

• Arguments are usually given within parenthesis after the function

seq(from=5, to=20, by=0.5)Function Arguments

Basic anatomy of an R command

Page 9: R basics workshop

• Names can be eliminated if arguments are given in predetermined orderseq(5, 20, 0.5)

seq(from=5, to=20, by=0.5)

• Arguments almost always have names (e.g., "from ", "to", etc.)

seq(by=0.5, to=20, from=5)• Arguments can be reordered if you use names

seq(0.5, 5, 20)

Basic anatomy of an R command

Page 10: R basics workshop

• Writing an R command is like writing a command in English

paste("R", "Basics", "Workshop")

rep(x="R", times=10)

Paste the words “R”, “Basics” and “Worshop”

Repeat “R” 10 times

sum(19, 4, 2, 6, 2)

Sum 19, 4, 2, 6 and 2

Basic anatomy of an R command

Page 11: R basics workshop

• Some functions can be used in other ways.

• E.g. the operator + must be used between values

sum(19, 4)

Sum 19 and 4

19 + 4

Sum 19 and 4

Basic anatomy of an R command

Page 12: R basics workshop

seq(from=5, to=20, by=0.5)

seq(to=10)

?seq

• Frequently, functions have arguments with predetermined values

• Predetermined arguments do not need to be specified

• You can find predetermined values in the help page

Arguments with predetermined values

Page 13: R basics workshop

• 1. Access help file for the function - RTFM

• 2. Make a search in www.rseek.org or Google

• 3. Ask a friend

• 4. Ask a question in an on-line discussion forum - http://www.r-project.org/mail.html

• 5. Have a look at the internal code of the function

Getting Help

Page 14: R basics workshop

?lm• 1. Access help file for the function by using ? or help()

• Critical components of the help pages:

• Usage – How to use the function

• Arguments – Description of arguments

• Details – Details on how the function works

• Value – Description of the output

• See Also – Other related functions

• Examples – Examples on how to use the function

help(lm)

Getting Help

Page 15: R basics workshop

• 2. Make a search in www.rseek.org

Getting Help

Page 16: R basics workshop

• 3. Ask a friend (that knows more than you do)

Getting Help

Iván Jiménez, Ph.D.Associate ScientistCenter for Conservation and Sustainable Development

office phone: + 1 (314) 577- 6566fax: + 1 (314) 577-9596email: [email protected]

Page 17: R basics workshop

• 4. Ask a question in an on-line r-project.org/mail.html

Getting Help

Page 18: R basics workshop

• 5. Have a look at the internal code of the function

• The name of the function without parenthesis produces the R code behind the function; e.g.:

lm

seq

• Some functions are not written in R and cannot be accessed this way; e.g.:

Getting Help

Page 19: R basics workshop

ArgumentsFunction

Predetermined argumentsOutput

seq(to=20, by=0.5)

Summary: functions and arguments

Page 20: R basics workshop

Exercise 2Functions and arguments


Recommended