1 / 20

R basics workshop

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.

tareq
Download Presentation

R basics workshop

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. R basics workshop J. Sebastián Tello Iván Jiménez Center forConservation and SustainableDevelopment Missouri Botanical Garden

  2. 3 fundamental concepts: • Function • Argument • Object

  3. 2. Functions and Arguments

  4. Writing in R is like writing in English Jump three times forward Action Modifiers

  5. Writing in R is like writing in English Generate a sequence from 5 to 20 with values spaced by 0.5 Action Modifiers

  6. Writing in R is like writing in English Action Modifiers Generate a sequence from 5 to 20 with values spaced by 0.5 seq(from=5, to=20, by=0.5) Function Arguments

  7. Basic anatomy of an R command Open parenthesis Close parenthesis Equal sign Comma seq(from = 5, to = 20, by = 0.5) Other arguments Argument value Argument name Function

  8. Basic anatomy of an R command seq(from=5, to=20, by=0.5) Function Arguments • 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 parenthesisafter the function

  9. Basic anatomy of an R command • Arguments almost always have names (e.g., "from ", "to", etc.) seq(from=5, to=20, by=0.5) • Names can be eliminated if arguments are given in predetermined order seq(5, 20, 0.5) seq(0.5, 5, 20) • Arguments can be reordered if you use names seq(by=0.5, to=20, from=5)

  10. Basic anatomy of an R command • Writing an R command is like writing a command in English Sum 19, 4, 2, 6 and 2 sum(19, 4, 2, 6, 2) Paste the words “R”, “Basics” and “Worshop” paste("R", "Basics", "Workshop") Repeat “R” 10 times rep(x="R", times=10)

  11. Basic anatomy of an R command • Somefunctions can be used in otherways. • E.g. theoperator+must be usedbetweenvalues Sum 19 and 4 Sum 19 and 4 sum(19, 4) 19 + 4

  12. Arguments with predetermined values seq(from=5, to=20, by=0.5) seq(to=10) • Frequently, functions have arguments with predetermined values • Predetermined arguments do not need to be specified • You can find predetermined values in the help page ?seq

  13. Getting Help • 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

  14. Getting Help • 1. Access help file for the function by using ? or help() ?lm help(lm) • 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

  15. Getting Help • 2. Make a search in www.rseek.org

  16. Getting Help • 3. Ask a friend (that knows more than you do) Iván Jiménez, Ph.D. Associate Scientist Center for Conservation and Sustainable Development office phone: + 1 (314) 577-6566 fax: + 1 (314) 577-9596 email: ivan.jimenez@mobot.org

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

  18. Getting Help • 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 • Some functions are not written in R and cannot be accessed this way; e.g.: seq

  19. Summary: functions and arguments seq(to=20,by=0.5) Function Arguments Output Predetermined arguments

  20. Exercise 2 Functions and arguments

More Related