Download - DeepDive R
-
PDF IDG Korea , .
IDG Korea PDF , .
R
R
R
R
I D G D e e p D i v e
R R . 4,400 18,000 R , 80 R
. R R
. R R
.
-
IDG Deep Dive | , R
R. 4,400(Add-on) , 18,000(Linkedin) R , 80R R , R.
R , R? R
. 2009R. R
R. R(RStudio). .
/(Reinhart/Rogoff) . . ., .
. R .R? R
. R . D. 10RR . . R
R
1 IT World
R Sharon Machlis | ComputerWorld
p a r t 1
-
IDG Deep Dive | , R
. , , .
R R
R . r-project.org (www.r-project.org) . OS X iOS.R (Integrated Development Environment)
R(RStudio). R (www.rstudio.com/ide)
. R4, , , R .. R
R . R . .,
. () . , , .
RR 3
.
- . . R
.
.
- + () ( + () ). .
.
. .
- + ( + ).
. / +
.
IT World 2
1 | R
R R .
-
IDG Deep Dive | , R
R R (www.rstudio.com/ide/docs).
setwd() .
setwd(~/mydirectory)
(\)(/).
setwd(C:/Sharon/Documents/RProjects)
R(Session) > (Set Working Directory) .
RCRAN(Comprehensive R Archive Network, http://cran.us.r-
project.org)R. .
install.packages(thepackagename)
R . (Install Packages) . .
installed.packages()
R . .
library(thepackagename)
. .
3 IT World
R
R, . . (Revolution Analytics) R .
- . .
- . 500 R .
- . R .- . R .
- . R .
-
IDG Deep Dive | , R
update.packages()
.
remove.packages(thepackagename)
.
?functionName
.
help(functionName)
help() ? ?functionName. .
example(functionName)
, . (args) args(functionName). R.
help.search(your search term)
.
??(my search term)
.
IT World 4
-
IDG Deep Dive | , R
RR. R. . R.
R(Data Set). R .
data()
() (Plotting) . .mtcars
. ( 360. ) , .
mtcars
. R print() R .
R(CSV, Comma-Separated Value)
. filename.txtCSV mydataR .
5 IT World
RSharon Machlis | ComputerWorld
p a r t 2
-
IDG Deep Dive | , R
mydata
-
IDG Deep Dive | , R
, R . , R(RStudio) , URL., RR
. , -- .
(Snippet) , +C
R. Header Row, , (x).
x
-
IDG Deep Dive | , R
. R? CSV
. , - - > . , URLURL. . . .
. CSV. R.
mydata
-
IDG Deep Dive | , R
install.packages(quantmod)
library(quantmod)
getSymbols(AAPL)
barChart(AAPL)
2? .
barChart(AAPL, subset=last 14 days)
chartSeries(AAPL, subset=last 14 days)
, .
barChart(AAPL[2013-04-01::2013-04-12])
Quantmod , Qunatmod (http://www.quantmod.com/examples/intro). twitteRR
. QuandlQuandl rdatamerket rga, RGoogleAnalytics ganalytic.R?
Quandl(www.quandl.com)Datamarket(http://datamarket.com). R .
x, rm()
.
rm(x)
,
. . , .? , R
(), . , .
9 IT World
-
IDG Deep Dive | , R
. . R , .
save.image()
.RData. .R, R. , R
. .RData. , .RData . R .
save(variablename, file=filename.rda)
.
load(filename.rda)
IT World 10
IT
IDG Tech LibraryIDG Tech Library IDG ,IT . Computer World, Info World, CIO,Network World IT
IDG Deep Dive, Tech Focus, Summary, World Update.
IDG() 1 108 4 100-161 Tel : 02-558-6950 Fax : 02-558-6955 www.itworld.co.kr www.twitter.com/ITWorldKR www.facebook.com/ITworld.Korea
-
IDG Deep Dive | , R
1, 2R R . ? .
R 2- - , . 1(Vector). .
head(mydata)
RmydataColumn Header()6. 610? .
head(mydata, n=10)
.
head(mydata, 10)
(1, 1, 2, 3, 5, 8, 13, 21, 34) 1 , head(mydata) 6. , tail() .
tail(mydata)
.
tail(mydata, 10)
tail() ,
11 IT World
Sharon Machlis | ComputerWorld
p a r t 3
-
IDG Deep Dive | , R
. , . R , str() .
str(mydata)
. , (
R (Observations)) (R ). str() (, , )
.8, [1:8].
. mydata, .
colnames(mydata)
, - - .
rownames(mydata)
R
. , summary() .
summary(mydata)
. , , , 1, 3, . , , , , (Factor), . summary() 1
. , psych . .
IT World 12
1 | PlantGrowth str()
2 | diamonds summary
-
IDG Deep Dive | , R
install.packages(psych)
. .
library(psych)
psych , R library . .
describe(mydata)
, , , () () .Rmean(), median(), min(), max(), sd() (), var() (),
1range(). (- , mean()median() -2)., mode() (Mode)
. mfv() ()modeest.R
. , , , , () . , cor() .
cor(mydata)
. . , R NA . ,summary()
, mean() 1NA. , NA.
na.rm=TRUE
13 IT World
3 |
-
IDG Deep Dive | , R
NA. .
mean(myvector, na.rm=TRUE)
, .
?median
na.rm . (Outlier) mean()(Trim) .R . , 15
4? 15! / 4! x 11! R choose() .
choose(15,4)
, 5. mypeople.
mypeople
-
IDG Deep Dive | , R
. 3 . R.,
(, 1, 2, 3, ). , mtcars
mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb.
? str(mtcars)head(mtcars) .
names(mtcars)
mtcars.colnames () .
mtcars.colnames
-
IDG Deep Dive | , R
. , mtcars$mpg ..
-- . , [, ]. , . mtcars 2 ~ 4, .
mtcars[,2:4]
2:4 ? , . , . 3 2 4, .
mtcars[,c(2,4)]
.
- R 0 1 . [0] [1].
- R . mtcars$mpg mtcars$MPG .
- mtcars[,-1]
. , R .
mtcars[, -1] .
- , c() . c mtcars[,
(2,4)] . c .
mtcars[,c(2,4)]
mpg > 20? .
mtcars$mpg>20
mpg20 . ,
IT World 16
-
IDG Deep Dive | , R
.
[1] TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE
[10] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
[19] TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE
[28] TRUE FALSE FALSE FALSE TRUE
, -- . .
mtcars[mtcars$mpg>20,]
Rmtcarsmpg > 20, . mpg20 mpg, .
mtcars[mtcars$mpg>20,c(1,4)]
.
mtcars[mtcars$mpg>20,c(mpg,hp)]
mpgmtcars$mpg? R . , .
17 IT World
-
IDG Deep Dive | , R
mpg20 20
cols 20, c(mpg, hp))
IT World 18
-
IDG Deep Dive | , R
mpg?
subset(mtcars, mpg==max(mpg))
mpgmpg .
subset(mtcars, mpg==max(mpg), mpg)
subset , .
subset(mtcars, , c(mpg, hp))
, select=.
subset(mtcars, select=c(mpg, hp))
, table . diamonds
, .
table(diamonds$cut)
- , , , . ?
table(diamonds$cut, diamonds$color)
R, . R (http://health.adelaide.edu.au/psychology/ccs/docs/lsr/lsr-0.3.pdf) . 500 PDF. , R CookbookR in a Nutshell .
19 IT World
5 | R table()
-
IDG Deep Dive | , R
R. , 2, . Rmtcars. disp xmpg y.
plot(mtcars$disp, mtcars$mpg)
. , .x y, xlab ylab . , main .
plot(mtcars$disp, mtcars$mpg, xlab=Engine displacement, ylab=mpg,
main=MPG compared with engine displacement)
y90 () , labs=1 .
plot(mtcars$disp, mtcars$mpg, xlab=Engine displacement, ylab=mpg,
main=MPG vs engine displacement, las=1)
las 1? las Label Stype , 4. 0, . 1, 2 2. (Plot) , .
?par
R,R .
IT World 20
Sharon Machlis | ComputerWorld
1 | R
p a r t 4
-
IDG Deep Dive | , R
. .
? , , . R .
ggplot2 ggplot2
. ggplot2 . , . ggplot2, .
install.packages(ggplot2)
. ggplot2 , library()R ggplot2 - R .
library(ggplot2)
ggplot2 . ggplot2 R plot() qplot() . .
qplot(disp, mpg, data=mtcars)
qplotRy. , y0 (y0). y, ylim .
qplot(disp, mpg, ylim=c(0,35), data=mtcars)
1. ,
21 IT World
2 | R
3 | Qplot() ggplot2
-
IDG Deep Dive | , R
ggplot2 .
qplot(cty, hwy, data=mpg)
geom jitter.
qplot(cty, hwy, data=mpg, geom=jitter)
, ggplot2, . ggplot(). , ggplot2 ggplot2() ggplot(). ggplot()plot()qplot(); .
ggplot(mtcars, aes(x=disp, y=mpg)) + geom_point()
ggplot() mtcars. . , aes()geom_point() ? aes (aesthetics)- , , . geom, , .,
. () ? R
geom_point() geom_line() .
ggplot(pressure, aes(x=temperature, y=pressure)) +
geom_line()
. pressure, , y=pressure pressure . , x y. , .Y ggplot ylim
. mydata, xcol x ycol y
IT World 22
4 |
-
IDG Deep Dive | , R
. ylim .
ggplot(mydata, aes(x=xcol, y=ycol), ylim=0) + geom_line()
.
ggplot(pressure, aes(x=temperature, y=pressure)) + geom_line() +
geom_point()
. , , . . (ggplot2)The Graphics Cookbook.
RBOD R barplot()
. BOD , .
barplot(BOD$demand)
main=Graph of demand.
barplot(BOD$demand, main=Graph of demand)
x, names.arg .
barplot(BOD$demand, main=Graph of demand, names.arg =
BOD$Time)
, . R table() .The R Graphics Cookbookmtcars 4-, 6-, 8-
. cyl, Rmtcars$cly. table()
. clycount.
23 IT World
5 | ggplot
temperature
pressure
-
IDG Deep Dive | , R
cylcount
-
IDG Deep Dive | , R
qplot(columnName, data=mydata, binwidth=n)
ggplot().
ggplot(mydata, aes(x=columnName)) + geom_histogram(binwidth=n)
ggplot() . ggplot(), , .
R. , 1, 3
(Boxplot)boxplot(). mtcars mpg boxplot .
boxplot(mtcars$mpg)
ggplot2x, y, z .
boxplot(diamonds$x, diamonds$y, diamonds$z)
R (Heat Map) , . FlowingData. Corrplot (http://cran.r-project.org/web/packages/corrplot/corrplot.pdf) (http://blog.revolutionanalytics.com/2013/03/rs-garden-of-probability-distributions.html). 6.
. , R
. RRGB , HSV(Hue, Saturation, Value. ,
) . , , , , . R 657. color() colour() - R- . , ,
25 IT World
-
IDG Deep Dive | , R
PDF . , .rainbowheatnR .
rainbow(n)
heat.colors(n)
terrain.colors(n)
topo.colors(n)
cm.colors(n)
rainbow 5, .
rainbow(5)
.
?rainbow
, ? . ggplot()3 rainbow 3. .
mycolors
-
IDG Deep Dive | , R
. R .
barplot(BOD$demand, col=rainbow(6))
(), ,
barplot(BOD$demand, col=royalblue3)
, . R , , .
testscores
-
IDG Deep Dive | , R
, . .
barplot(testscores, col=testcolors, main=Test scores)
y0100.
barplot(testscores, col=testcolors, main=Test scores, ylim=c(0,100))
90las=1.
barplot(testscores, col=testcolors, main=Test scores, ylim=c(0,100), las=1)
, ., ,
testscores .
testscores
-
IDG Deep Dive | , R
qplot(factor(cyl), data=mtcars, geom=bar, fill=factor(cyl))
, , R. R (www.harding.edu/fmccown/r/) . The R Graphics Cookbook(www.amazon.com/R-Graphics-Cookbook-Winston-Chang/dp/1449316956) . ggplot2 (http://docs.ggplot2.org/current/geom_bar.html) .
R R . R
. R,
. R , jpeg(), png(),
svg() pdf() (Container). .
jpeg(myplot.jpg, width=350, height=420)
.
barplot(BOD$demand, col=rainbow(6))
.
dev.off()
. ggplot2 ,ggsave() , ggplot2. ggsave() - myplot.jpg JPEG, myplot.pngPNG .
R, . , .
29 IT World
11 |
12 | R
-
IDG Deep Dive | , R
R . , . R. (=)
. , x = 3x3. R. . R
-
IDG Deep Dive | , R
int myArray = {1, 1, 2, 3, 5, 8};
, .
myArray = [1, 1, 2, 3, 5, 8]
, R. c() .
my_vector
-
IDG Deep Dive | , R
My_list
-
IDG Deep Dive | , R
. lapply() tapply() apply() /. , F.W. R (http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/) ., , .apply R for ,
plyr . --. , ().plyr . plyr
, plyr (http://plyr.had.co.nz). , plyr PDF (www.stat.cmu.edu/~cshalizi/statcomp/11/lectures/14/lecture-14.pdf).
R R?
R , . . ., . R
. . ., R true/false
. R, , , . NaN() NA(). .
1, 5, 7
Bill, Bob, Sue
. , .
33 IT World
-
IDG Deep Dive | , R
[1]
1. , , . TRUE/FALSE
, . ( , (3, 8,small) (3, 8,small)
). , R 3 3.0. 33L as,integer() . ,class() .
class(3)
class(3.0)
class(3L)
class(as.integer(3))
as.character(), as.list() as.data.frame() as() . R. . dim().
dim(my_matrix)
. , . (), R.
. , summary() psych describe() ..
, . , class() str()data.frame, mode().. (factor).
IT World 34
1 | 1
-
IDG Deep Dive | , R
. , , () . . , , .
R R , . , R
, .? R
(). list(), . , R . ? pwd. gwtwd().rm(my_variable). R grep()
. Rgrep regular-expressions.infoR (www.regular-expressions.info/rlanguage.html) .
R (Expression) R (
, ). , R(, ).? R (Interpreter)
. , R . , +- . R.
: R SQL SQLR - , R
- SQLSELECT .. sqldfR SQL
.(R).sqldf, .
35 IT World
-
IDG Deep Dive | , R
sqldf(select * from mtcars where mpg > 20 order by mpg desc)
mtcarsmpg 20 mpgmpg . R R. SQLR . , . R .
GUI ,
, R . edit() R .
edit(mtcars)
. , - -
, /. R() .
save.image() R
, . , , , .
write.table(myData, testfile.txt, sep=\t)
myDataR testfile.txt. sep=\t sep=\c.
IT World 36
2 | edit() R
-
IDG Deep Dive | , R
. R, , , /, /. Introduction to Data Science(, http://jsresearch.net/wiki/projects/
teachdatascience) : , . ? R , R. , (ROAuth ) , (Map Mashup)R. , . iOS PDF - iOS . .
R Cookbook : (OReilly)Cookbook , R, . . R ,
. (quantitative developer).
R Graphics Cookbook : R, ggplot2. R, , . R.
R in a Nutshell : R - , , - . , R
37 IT World
Sharon Machlis | ComputerWorld
p a r t 6
-
IDG Deep Dive | , R
R . .
Visualize This : R, R. . Flowing Data().
R For Dummies : , .(Dummies) , . Dimmies.com R , R R apply 100. .
Exploring Everyday Things with R and Ruby : , . . , ggplot2 R. , R.
Cookbook for R(www.cookbook-r.com) : R Cookbook
, (R Graphics Cookbook ) , . Cookbook . ,?.
Quick-R(www.statmethods.net) : . , (Stats)(Frequencies and Crosstab)table() . (R )(). R in Action(R)I. .
R Reference Card(http://cran.r-project.org/doc/contrib/Short-refcard.pdf) :, (2004) 4
IT World 38
-
IDG Deep Dive | , R
PDF . EPRI(Electric Power Research Institute: ) .
A short list of R the most useful commands(http://www.personality-project.
org/R/r.commands.html) : , R(Using R for psychological research) .HTML . 2005 ..
Chart Chooser in R(www.maths.lancs.ac.uk/~rowlings/Teaching/UseR2012/
cheatsheet.html) : , , , R . ,, . (Juice LabsChart Choser).
Twotorials(www.twotorials.com) : 2 (Twotorial)
. 2, . R R 2 2 R. R 10, 15, 20,000. , .
Up and Running with R(www.lynda.com/R-tutorials/Up-Running-R/120612-
2.html) : Lynda.com R , , . , . Lynda.com25, 7.
Coursera: Computing for Data Analysis(www.coursera.org/course/compdata)
: . . 2013 9. , ; . , ,
39 IT World
-
IDG Deep Dive | , R
.
Coursera: Data Analysis : RR. R
, . , .
Coursera: Statistics One(www.coursera.org/course/stats1) : 9 R 12
, . R R . .
Try R(http://tryr.codeschool.com) :
. , , R .
An Introduction to R(http://cran.r-project.org/doc/manuals/R-intro.pdf) : RProject . R . Dl , R Core Team, .
Learning statistics with R(http://health.adelaide.edu.au/psychology/ccs/
docs/lsr/lsr-0.3.pdf) : (PDF). ANOVA(ANalysis Of Variance: , )500. , R.
R Tutorial(www.cyclismo.org/tutorial/R/) : , , p, . .
IT World 40
-
IDG Deep Dive | , R
r4stats.com(http://r4stats.com) : R R. , ggplotsR . R SAS SPSS .
Getting started with charts in R(http://flowingdata.com/2012/12/17/getting-
started-with-charts-in-r) : FlowingData R(FlowingData , 20135.)
Using R for your basic statistical Needs LISA Short Course(www.lisa.stat.vt.
edu/sites/default/files/Using_R_for_Your_Basic_Statistical_Needs.r) : , RR () . , , . . -2log(Likelihood) +
kp?AIC#step() .k=2 # p = ( ). (Laboratory for Interdisciplinary
StatisticalAanalysis) .
Producing Simple Graphs with R(www.harding.edu/fmccown/r) : 6, . .
Short courses(http://courses.had.co.nz) : Rggplot2R .
Quick introduction to ggplot2(http://blog.echen.me/2012/01/17/quick-
introduction-to-ggplot2/) : , - - R ggplot2 ..
ggplot2_tutorial.R(http://rpubs.com/frank_davenport/6255) : RPubs.com R , R
41 IT World
-
IDG Deep Dive | , R
ggplot2.
More and Fancier Graphics(http://ww2.coastal.edu/kingw/statistics/R-
tutorials/graphs.html) : 1R R , locator() identify() . B. .
Using R(www.sr.bham.ac.uk/~ajrs/R/index.html) : , . R ,Lattis ggplot2. . ASR(Astrophysics & SpaceResearch) .
The Undergraduate Guide to R(https://sites.google.com/site/undergraduat
eguidetor/manual-files) : , ,, , R . PDF , . NIH.
Introducing R(www.ats.ucla.edu/stat/r/seminars/intro.htm) : UCLA
.
Introducing R(http://data.princeton.edu/R/gettingStarted.html) : .
R: A self-learn tutorial(www.nceas.ucsb.edu/files/scicomp/Dloads/RProgra
mming/BestFirstRTutorial.pdf) : UC PDF. , .
Statistics with R Computing and Graphics R(www.stats.ox.ac.uk/~konis/
OUCS/ComputingGraphics.pdf) : ). PDF, PDF (15) , R() . .
Little Book of R for Time Series (http://a-little-book-of-r-for-time-series.
IT World 42
-
IDG Deep Dive | , R
readthedocs.org/en/latest) : R . .
Introduction to ggplot2(http://heather.cs.ucdavis.edu/~matloff/GGPlot2/
GGPlot2Intro.pdf) : UC N. 11PDF ggplot.
Statistics and R on Google+(https://plus.google.com/communities/117681470
673972651781) : .
Twitter #rstats hashtag(https://twitter.com/search?q=%23rstats) : , R . , (Reddit) R .
Stackoverflow(http://stackoverflow.com/questions/tagged/r) : R . , . R . , Meetup.com. R .
R
, R. . RSeek(www.rseek.org)R
. R site search(http://finzi.psych.upenn.edu/search.
html)R , () ().
Googles R Style Guide(http://google-styleguide.
googlecode.com/svn/trunk/google-r-style.html) : ?
43 IT World
-
IDG Deep Dive | , R
; R . , R .
RStudio documentation(www.rstudio.com/ide/docs/) : R, .
History of R Financial Time Series Plotting(http://timelyportfolio.github.io/
rCharts_time_series/history.html) : , , . . .
Comprehensive R Archive Network(CRAN, http://cran.r-project.org) :
. R , FAQ R . .
RStudio(www.rstudio.com) : R RStudioShiny RStudio IDE.
Revolution Analytics(www.revolutionanalytics.com/) : R , R (). 2R .
Tibco(www.tibco.com) : Dl R Tibco EnterpriseRuntime for R Engines Tibco Enterprise Runtime for R DevelopersEdition.
IT World 44