syntax.us
Let the syntax do the talking
|
Blog
Contact
Posts
Questions
Tags
Hire Me
|
Question:
How to install ISLR R Package on Ubuntu 14.04?
I am currently reading a book: "An Introduction to Statistical Learning"
I found it at the URL listed below:
http://www-bcf.usc.edu/~gareth/ISL/
The book has a companion R package which I just installed on my Ubuntu Laptop.
I started by creating a folder for the R package:
mkdir -p ~/ks/b/hastie/rpkgs
cd ~/ks/b/hastie/
Next I created a script named demoISLR.r with a few lines of R syntax:
# demoISLR.r
# I should run this syntax inside R (once):
# install.packages("ISLR", lib="rpkgs", repos="http://cran.us.r-project.org")
# Now I can do this in my scripts:
# Next, tell this script where it is:
.libPaths("rpkgs")
# Now I can use it
library(ISLR)
myauto = Auto
summary(myauto)
I started R and ran this command from the R command line:
install.packages("ISLR", lib="rpkgs", repos="http://cran.us.r-project.org")
I exited R and ran this shell command:
R -f insISLR.r
It worked well and I saw this:
dan@nia111:~/ks/b/hastie $
dan@nia111:~/ks/b/hastie $
dan@nia111:~/ks/b/hastie $ R -f demoISLR.r
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> # demoISLR.r
>
> # I should run this syntax inside R (once):
> # install.packages("ISLR", lib="rpkgs", repos="http://cran.us.r-project.org")
>
> # Now I can do this in my scripts:
>
> # Next, tell this script where it is:
> .libPaths("rpkgs")
>
> # Now I can use it
>
> library(ISLR)
>
> myauto = Auto
> summary(myauto)
mpg cylinders displacement horsepower weight
Min. : 9.00 Min. :3.000 Min. : 68.0 Min. : 46.0 Min. :1613
1st Qu.:17.00 1st Qu.:4.000 1st Qu.:105.0 1st Qu.: 75.0 1st Qu.:2225
Median :22.75 Median :4.000 Median :151.0 Median : 93.5 Median :2804
Mean :23.45 Mean :5.472 Mean :194.4 Mean :104.5 Mean :2978
3rd Qu.:29.00 3rd Qu.:8.000 3rd Qu.:275.8 3rd Qu.:126.0 3rd Qu.:3615
Max. :46.60 Max. :8.000 Max. :455.0 Max. :230.0 Max. :5140
acceleration year origin name
Min. : 8.00 Min. :70.00 Min. :1.000 amc matador : 5
1st Qu.:13.78 1st Qu.:73.00 1st Qu.:1.000 ford pinto : 5
Median :15.50 Median :76.00 Median :1.000 toyota corolla : 5
Mean :15.54 Mean :75.98 Mean :1.577 amc gremlin : 4
3rd Qu.:17.02 3rd Qu.:79.00 3rd Qu.:2.000 amc hornet : 4
Max. :24.80 Max. :82.00 Max. :3.000 chevrolet chevette: 4
(Other) :365
>
>
dan@nia111:~/ks/b/hastie $
dan@nia111:~/ks/b/hastie $
dan@nia111:~/ks/b/hastie $
The above output shows that I have access to some data inside ISLR called Auto.
This data is about cars made in the 1970s and early 1980s.
Also the above output shows the behavior of a useful R function called summary() which can
display aggregated calculations of collections of either strings or numbers.
For example, summary() shows the minimum year is 70 and the maximum year is 82.
|
syntax.us
Let the syntax do the talking
|
Blog
Contact
Posts
Questions
Tags
Hire Me
|