Getting Started with R · 2017. 7. 13. ·...
Transcript of Getting Started with R · 2017. 7. 13. ·...
![Page 1: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/1.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 1
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
12 July 2017 "Dr. Norhaiza Ahmad"
Department of Mathematical Sciences"Faculty of Science"
Universiti Teknologi Malaysia"
Getting Started with R!for newbies!
!PART B: !
FUNCTIONS-PACKAGES-HELP!!12 July 2017 "
Dr. Norhaiza Ahmad"Department of Mathematical Sciences"
Faculty of Science"Universiti Teknologi Malaysia"
http://science.utm.my/norhaiza/!
![Page 2: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/2.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 2
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Outline
PART B: Core of R 1. R func-ons (in-‐built) 2. R Packages 3. How to search for Func-on/Packages etc
![Page 3: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/3.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 3
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Outline
PART B: Core of R 1. R funcNons (in-‐built) 2. R Packages 3. How to search for Func-on/Packages etc
![Page 4: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/4.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 4
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Func-ons in R
• R commands are executed by running a func-on • A func-on is a name, which is typed followed by a pair
of brackets. Arguments are added inside the brackets > sqrt(2) > sin(pi) • Some-mes func-ons in R have extra argument. > sum(2,3,5) > log(10,10)
• R has many in-‐built func-ons. • These func-ons can also be programmed manually
![Page 5: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/5.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 5
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Examples of Other Func-ons in R
FUNCTIONS OperaNon sqrt Square root abs Absolute value cos tan Trigonometric func-ons (radians) sinh cosh tanh hyperbolic func-ons Asinh acosh atanh inverse hyperbolic func-ons exp log log10
exponen-al ,natural logarithm common logarithm
• What are other func-ons in R?
• Where to find other func-ons?
These func-ons can be nested and combined to make more complex expressions:
> sqrt(sin(45*pi/180)) [1] 0.8408964
![Page 6: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/6.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 6
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Outline
PART B: Core of R 1. R func-ons (in-‐built) 2. R Packages 3. How to search for Func-on/Packages etc
![Page 7: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/7.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 7
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Packages in R ● a package is a collec-on of R func-ons, data and compiled
codes. ● Different packages cater for different purposes that can be
reused by others.
Every R package is simply a bundle of code that serves a specific purpose and is designed to be reusable by other developers. In addi-on to the primary codebase, packages o^en include data, documenta-on, and tests. As an R user, you can simply download a par-cular package (some are even pre-‐installed) and start using its func-onali-es. Everyone can develop R packages, and everyone can share their R packages with others. The above is an extremely powerful concept and one of the key reasons R is so successful as a language and as a community. Namely, you don’t need to do all the hard core programming yourself or understand every complex detail of a par-cular algorithm or visualiza-on. You can simple use the out-‐of-‐the box func-ons that come with the relevant package as an interface to such func-onali-es. As such it is useful to have an understanding of R’s package ecosystem. Many R packages are available from the Comprehensive R Archive Network, and you can install them using the install.packages func-on. What is great about CRAN is that it associates packages with a par-cular task via Task Views. Alterna-vely, you can find R packages on bioconductor, github and bitbucket. Looking for a par-cular package and corresponding documenta-on? Try Rdocumenta-on, where you can easily search packages from CRAN, github and bioconductor.
Powerful concept-‐ successful as a language community – No need to do heavy programming on your own – can use packages/func-ons freely
Concept: Anyone Can Develop à Share
R Package 2
R func-on 1
R func-on 2
R func-on n
R Package 2
R func-on 1
R func-on 2
R func-on n
Simple structure of package/func-ons in R in a nutshell
![Page 8: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/8.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 8
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Packages in R ● Different packages cater for different purposes that can be reused by others. Ø R comes with a pre-‐installed set of packages Ø There are many other packages that can be
downloaded.
Every R package is simply a bundle of code that serves a specific purpose and is designed to be reusable by other developers. In addi-on to the primary codebase, packages o^en include data, documenta-on, and tests. As an R user, you can simply download a par-cular package (some are even pre-‐installed) and start using its func-onali-es. Everyone can develop R packages, and everyone can share their R packages with others. The above is an extremely powerful concept and one of the key reasons R is so successful as a language and as a community. Namely, you don’t need to do all the hard core programming yourself or understand every complex detail of a par-cular algorithm or visualiza-on. You can simple use the out-‐of-‐the box func-ons that come with the relevant package as an interface to such func-onali-es. As such it is useful to have an understanding of R’s package ecosystem. Many R packages are available from the Comprehensive R Archive Network, and you can install them using the install.packages func-on. What is great about CRAN is that it associates packages with a par-cular task via Task Views. Alterna-vely, you can find R packages on bioconductor, github and bitbucket. Looking for a par-cular package and corresponding documenta-on? Try Rdocumenta-on, where you can easily search packages from CRAN, github and bioconductor.
When you download and install R, you would have auto downloaded and installed the base and selected packages.
![Page 9: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/9.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 9
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Example of Packages in R Every R package is simply a bundle of code that serves a specific purpose and is designed to be reusable by other developers. In addi-on to the primary codebase, packages o^en include data, documenta-on, and tests. As an R user, you can simply download a par-cular package (some are even pre-‐installed) and start using its func-onali-es. Everyone can develop R packages, and everyone can share their R packages with others. The above is an extremely powerful concept and one of the key reasons R is so successful as a language and as a community. Namely, you don’t need to do all the hard core programming yourself or understand every complex detail of a par-cular algorithm or visualiza-on. You can simple use the out-‐of-‐the box func-ons that come with the relevant package as an interface to such func-onali-es. As such it is useful to have an understanding of R’s package ecosystem. Many R packages are available from the Comprehensive R Archive Network, and you can install them using the install.packages func-on. What is great about CRAN is that it associates packages with a par-cular task via Task Views. Alterna-vely, you can find R packages on bioconductor, github and bitbucket. Looking for a par-cular package and corresponding documenta-on? Try Rdocumenta-on, where you can easily search packages from CRAN, github and bioconductor.
ggplot2: fancy plots . MICE: Takes care of your Missing Values . nortest: normality tests . AER: Applied Econometrics with R. hddtools: analyse hydrological data #March 2017
Packages can be found from: • Comprehensive R Archive Network (CRAN)
• bioconductor • Github
![Page 10: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/10.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 10
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Handy Tip
• How to check which packages are available locally on your R?
>library()
![Page 11: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/11.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 11
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
How to load up an R package Need to call up its library!!
>#library(name of package) >#example
>library(stats)
Package: stats
acf
acf2.AR
t.test
![Page 12: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/12.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 12
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
How to use a package already in your R Every R package is simply a bundle of code that serves a specific purpose and is designed to be reusable by other developers. In addi-on to the primary codebase, packages o^en include data, documenta-on, and tests. As an R user, you can simply download a par-cular package (some are even pre-‐installed) and start using its func-onali-es. Everyone can develop R packages, and everyone can share their R packages with others. The above is an extremely powerful concept and one of the key reasons R is so successful as a language and as a community. Namely, you don’t need to do all the hard core programming yourself or understand every complex detail of a par-cular algorithm or visualiza-on. You can simple use the out-‐of-‐the box func-ons that come with the relevant package as an interface to such func-onali-es. As such it is useful to have an understanding of R’s package ecosystem. Many R packages are available from the Comprehensive R Archive Network, and you can install them using the install.packages func-on. What is great about CRAN is that it associates packages with a par-cular task via Task Views. Alterna-vely, you can find R packages on bioconductor, github and bitbucket. Looking for a par-cular package and corresponding documenta-on? Try Rdocumenta-on, where you can easily search packages from CRAN, github and bioconductor.
Once installed, you need to load the package
>library(stats)
Choose desired packages #pop-‐up window. OK
Loading an R package >#library(name of package) >#example
![Page 13: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/13.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 13
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
How to use a package NOT available in your R Every R package is simply a bundle of code that serves a specific purpose and is designed to be reusable by other developers. In addi-on to the primary codebase, packages o^en include data, documenta-on, and tests. As an R user, you can simply download a par-cular package (some are even pre-‐installed) and start using its func-onali-es. Everyone can develop R packages, and everyone can share their R packages with others. The above is an extremely powerful concept and one of the key reasons R is so successful as a language and as a community. Namely, you don’t need to do all the hard core programming yourself or understand every complex detail of a par-cular algorithm or visualiza-on. You can simple use the out-‐of-‐the box func-ons that come with the relevant package as an interface to such func-onali-es. As such it is useful to have an understanding of R’s package ecosystem. Many R packages are available from the Comprehensive R Archive Network, and you can install them using the install.packages func-on. What is great about CRAN is that it associates packages with a par-cular task via Task Views. Alterna-vely, you can find R packages on bioconductor, github and bitbucket. Looking for a par-cular package and corresponding documenta-on? Try Rdocumenta-on, where you can easily search packages from CRAN, github and bioconductor.
● Suppose the package is not available in In order to use an R package, it must be installed locally and then load #requires internet
Once installed, you need to load the package as before
At the ribbon, select tab <Packages> Choose <Install package(s)> Choose any CRAN mirror #pop-‐up window Choose desired packages #pop-‐up window. OK
>library(name of package)
![Page 14: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/14.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 14
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Outline
PART B: Core of R 1. R func-ons (in-‐built) 2. R Packages 3. How to search for FuncNon/
Packages etc
![Page 15: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/15.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 15
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
How to search for funcNon/packages in R
Func-on/Packages?
R-‐help!
hmps://www.rdocumenta-on.org/
Google it!
![Page 16: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/16.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 16
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Use Help! in R
• Help: R func-on name KNOWN • Help: R func-on name NOT KNOWN
Help pages in R will tell you the source package of the func-on, describe the func-ons, give you the syntax argument, explana-on about the arguments and example. These func-ons can be nested and combined to make more complex expressions: > sqrt(sin(45*pi/180)) [1] 0.8408964
![Page 17: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/17.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 17
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Use Help! in R
There are many in-‐built func-ons in R, each with different individual arguments. We can seek help in R to learn more about these func-ons.
A) Help: R func-on name KNOWN > help(nameOffunction) > help(log) #help on function log > ?log #help on function log
or at the Ribbon select > Help >R func-ons (text)
Exercise: Obtain help on the R func-on “plot”
![Page 18: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/18.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 18
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Handy Tip
• If your help document fails to upload (url fails etc), type
> op-ons(help_type=“text”) #a text version of the help document will be displayed
18
![Page 19: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/19.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 19
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Help in R (R func-ons)
Use Help: R func-ons if you know the name of the func-ons used and need more info about it
Help: R funcNon name KNOWN
![Page 20: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/20.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 20
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Illustrate an R Help document
!!!!!!Output: Attach: see !help plot document!!
Exercise: Obtain help on the R func-on “plot”
![Page 21: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/21.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 21
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Func-on: plot Package: graphics
How to use the func-ons and what are its arguments
![Page 22: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/22.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 22
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
• Examples for the Rfunc-on • We can copy and paste the
codes on Rconsole • Recommended to run line by line
![Page 23: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/23.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 23
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Use Help! in R
There are many in-‐built func-ons in R, each with different individual arguments. We can seek help in R to learn more about these func-ons.
B) Help: R func-on name NOT KNOWN > help.start( ) or at the Ribbon select > Help >Search help... > help.search(“optimization”) > ?? Exercise: Find an R func-on that would calculate the inverse of a matrix
![Page 24: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/24.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 24
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Help in R (Search help)
• Use Search Help if you do not know the func-ons use in R
• Shows a list of related func-ons
• Then use help(“name of func-on”)
Help: R funcNon name NOT KNOWN
![Page 25: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/25.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 25
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Illustrate an R Help document
!!!!!!
Exercise: 1. Obtain help on sta-s-cal significance to find
difference between two popula-on means called Student t-‐test
2. Find an R func-on that would calculate the
inverse of a matrix
![Page 26: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/26.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 26
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Example of help search
stats: t.test
Name of Package
Name of func-on
![Page 27: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/27.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 27
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Once you have idenNfied the funcNon-‐ get help for the funcNon:
> ?t.test!
![Page 28: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/28.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 28
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
IMPORTANT:
t.test{stats}
In order to use any R func-on (even the help documenta-on for the func-on), you need to make sure that (1) the package has already been installed locally in your computer (2) The library (or door) to the package needs to be opened
The loca-on where the packages are stored in your computer a^er it is downloaded is called the library.
If you can’t open your library, this implies that the package is not in your R. Thus, you need to install the package first.!
![Page 29: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/29.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 29
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
Once you have installed the package and open its library, -‐ you can use / get help for the funcNon:
> ?t.test!
![Page 30: Getting Started with R · 2017. 7. 13. · Workshop:)Ge,ng)Started)with)R.)UiTM)12)July)2017).©)Dr.)Norhaiza)Ahmad) 12 July 2017 "Dr. Norhaiza Ahmad" Department of Mathematical Sciences"](https://reader036.fdocuments.us/reader036/viewer/2022071105/5fdf3f9acc061e3071358245/html5/thumbnails/30.jpg)
www.utm.my innova-ve ● entrepreneurial ● global 30
Workshop: Ge,ng Started with R. UiTM 12 July 2017 .© Dr. Norhaiza Ahmad
NEXT
● PART C: Data Object Structure in R