SlideShare uma empresa Scribd logo
1 de 23
Alberto Minetti
What is R?
• Functional programming language
• Matrix-based
• Interpreted (written in C and Fortran)
• Environment for statistical computing and graphics
• Open source and GPL license
• 6000+ packages in CRAN
Why use R?
• Matrix calculation
• Data visualization (interactive too)
• Statistic analysis (regression, time series, geo-spatial)
• Data mining, classification, clustering
• Analysis of genomic data
• Machine learning
Who uses R?
• Oracle integrates R in its Big Data Appliance
• IBM offers support for in-Hadoop execution of R
• Data analysts for Google and Apple
• 12° in TIOBE popularity index
How to use R?
• Command-line interface, autonomous script or graphical front-ends
• Connection to any data source
• Data analysis
• Modeling and computation
• Data visualization
• Fitting models or displaying data
R Studio IDE
• licence AGPL 3
• Scripts
• Workspace
• Console
• Images
Reading and writing data
• From/To plain text files
• From/To Excel files
• From/To Databases
• From the Web
> heisenberg <- read.csv(file="simple.csv",head=TRUE,sep=",")
> write.csv(x=data, file="simple.csv")
> library(gdata)
> mydata = read.xls("mydata.xls")
> write.xlsx(x=data, file="simple.csv«)
> library(XLConnect)
> wk = loadWorkbook("mydata.xls")
> df = readWorksheet(wk,sheet="Sheet1")
> library(RPostgreSQL)
> con <- dbConnect(dbDriver("PostgreSQL"), dbname = "abc", user="postgres")
> q <- dbGetQuery(con, "SELECT * FROM prices WHERE x > 0")
> dbSendQuery(con, “INSERT INTO forecasts VALUE (10)")
> fpe <- read.table("http://data.princeton.edu/wws509/datasets/effort.dat")
Programming features
• Flow control statements
• while, repeat, break, continue, if, return
• Exceptions, using try catch blocks
• Functions
• Default parameters
• Positional or named arguments
• Generic
• Anonymous
fibonacci <- function(n) {
if(n<=2) return 1
fib <- numeric(n)
fib[1:2] <- 1
for(i in 3:n) {
fib[i] <- fib[i-1] + fib[i-2]
}
return (fib[n])
}
arr <- function(a = 1, b = 2) {
c(a, b)
}
> arr(b=6)
[1] 1 6
f3 <- function(f) { f(3) }
f3(function(x) {x*7})
`%my%` <- function(a,b) {
return 2*a + 2 *b
}
Correlation
mpg hp cyl
Mazda RX4 21.0 110 6
Mazda RX4 Wag 21.0 110 6
Datsun 710 22.8 93 4
Hornet 4 Drive 21.4 110 6
Hornet Sportabout 18.7 175 8
Valiant 18.1 105 6
Duster 360 14.3 245 8
Merc 240D 24.4 62 4
Merc 230 22.8 95 4
Merc 280 19.2 123 6
Merc 280C 17.8 123 6
Merc 450SE 16.4 180 8
Merc 450SL 17.3 180 8
Merc 450SLC 15.2 180 8
Cadillac Fleetwood 10.4 205 8
Lincoln Continental 10.4 215 8
Chrysler Imperial 14.7 230 8
Fiat 128 32.4 66 4
Honda Civic 30.4 52 4
Toyota Corolla 33.9 65 4
Toyota Corona 21.5 97 4
Dodge Challenger 15.5 150 8
AMC Javelin 15.2 150 8
Camaro Z28 13.3 245 8
Pontiac Firebird 19.2 175 8
Fiat X1-9 27.3 66 4
Porsche 914-2 26.0 91 4
Lotus Europa 30.4 113 4
Ford Pantera L 15.8 264 8
Ferrari Dino 19.7 175 6
Maserati Bora 15.0 335 8
Volvo 142E 21.4 109 4
> mtcars2 <- subset(mtcars,
select=c("mpg", "hp", "cyl"))
> pairs(mtcars2)
Auto-correlation
> A <- read.table(“http://cdiac.ornl.gov/ftp/trends/co2/maunaloa.co2”)
> X=t(A[1,])
> ts.plot(X)
> acf(X)
Plotting
> x <- seq(-1.57,1.57,by=.001)
> y <- (sqrt(abs(cos(x))) * cos(200*x) +
sqrt(abs(x))-0.7) * (4-x * x)^0.01
> plot(0,0, type=‘n’,
xlim=c(-2,+2),ylim=c(-1.6,+1.1))
> lines(x,y,col='pink')
> spread <- seq(1, length(x),
length.out=length(x)/10)
> cols <- c('yellow','red','orange', 'purple')
> text(x[spread],y[spread], label='love',
col=sample(rep(cols, length.out=length(spread))), cex=1)
Regression
> library("MASS")
> str(cats)
'data.frame': 144 obs. of 3 variables:
$ Sex: Factor w/ 2 levels "F","M": 1 1 1 1 1 1 1 1 1 1 ...
$ Bwt: num 2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ...
$ Hwt: num 7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ...
attach(cats)
> lm.out <- lm(Hwt ~ Bwt)
Call:
lm(formula = Hwt ~ Bwt)
Coefficients:
(Intercept) Bwt
-0.3567 4.0341
> plot(Hwt ~ Bwt, main="Kitty Cat Plot")
> abline(lm.out, col="red")
Data manipulation: discretisation
> clinical.trial <- data.frame(patient = 1:100, age= rnorm(100, mean = 60, sd = 8),
year.enroll = sample(paste("19", 85:99, sep = ""), 100, replace = TRUE))
> c1 <- cut(clinical.trial$age, breaks = 4)
> table(c1)
(41.1,50] (50,58.8] (58.8,67.6] (67.6,76.4]
9 34 41 16
> hist(clinical.trial$age, breaks=seq(40,100, by=10))
Plots from my MSc thesis
• Prices of energy in the Italian
Power Exchange spot market
• Forecast using a SARIMA model
Performances
• Good performances with built-in math functions
• Possibility to monitor the memory usage
• Possibility to offload data to an external DB to speed up large operations
• Functions for big data sets
• Parallel computation
Credits
• http://adv-r.had.co.nz/
• http://cran.r-project.org/
• http://simplystatistics.org/2013/02/15/interview-with-nick-
chamandy-statistician-at-google/
• https://kaosktrl.wordpress.com/2010/02/04/r-lanalisi-delle-serie-
storiche-partendo-da-copenaghen/
Vector part 1
> x <- c(2,5,9.5,-3) #create a vector
> x[2] #selects the second element
[1] 5
> x[c(2,4)] #select the elements in position 2 and 4
[1] 5 -3
> x[-c(1,3)] #keep out the elements in position 1 and 3
[1] 5 -3
> x[x>0] #select only positive elements
[1] 2.0 5.0 9.5
> x[!(x<=0)] #keep out the striclty not positve elements
[1] 2.0 5.0 9.5
> x[x>0]-1 > x[x>0]+c(1,2,3) #sum element-wise
[1] 1.0 4.0 8.5 [1] 3.0 7.0 11.0
> x[x>0][2]
[1] 5
Vector part 2
> which(x>0) #show the indexes that match the condition
[1] 1 2 3
> which.max(x) > which.min(x) > length(x)
[1] 4 [1] 3 [1] 4
> x<-1:10 > paste(1:5, c("A","B"), sep="")
[1] 1 2 3 4 5 6 7 8 9 10 [1] "1A" "2B" "3A" "4B" "5A"
> x1<-seq(1,1000, length=10) #vector from 1 to 1000 with step 10
[1] 1 112 223 334 445 556 667 778 889 1000
> x2<-rep(2,times=10) #repeat 2 10 times
[1] 2 2 2 2 2 2 2 2 2 2
> rep(c(1,3),times=4) #repeat (1,3) 4 times
[1] 1 3 1 3 1 3 1 3
> rep(c(1,9),c(3,1)) #repeat (1,9) 3 and 1 times respectively
[1] 1 1 1 9
> length(c(x,x1,x2,3))
[1] 31 #see also sort, order, eigen
Matrix part 1
> x<-matrix(1:10,ncol=5) #create
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
> x[,1] #select the first column
[1] 1 2
> x[,4:5] #select columns 4 and 5
[,1] [,2]
[1,] 7 9
[2,] 8 10
> cbind(1:2,c(1,-2),c(0,9)) #combine vectors by columns/rows (rbind)
[,1] [,2] [,3]
[1,] 1 1 0
[2,] 2 -2 9
> x[2,]<-rep(2,5)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 2 2 2 2
> x[2,] #select the second row
[1] 2 4 6 8 10
> x[,-c(2,4)] #select columns 1 3 5
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
Matrix part 2
> X<-diag(1:3)
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 2 0
[3,] 0 0 3
> solve(X) #the inverse of X
[,1] [,2] [,3]
[1,] 1 0.0 0.0000000
[2,] 0 0.5 0.0000000
[3,] 0 0.0 0.3333333
> X%*%solve(X)#....verify
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
List, can contain different object types
> lista<-list(matrix(1:9,nrow=3),rep(0,3),c(‘good’,’bad’))
> length(lista)
[1] 3
> lista[[3]] #third element
[1] ‘good’ ‘bad’
> length(lista[[3]])
[1] 2
> lista[[2]]+2 #sum on the second item
[1] 2 2 2
> lista[[1]][2,2]
[1] 5
> names(lista)<-c(‘first’, ‘second’, ‘third’) #names for elements
> lista$second #or lista[[second]] return a vector
[1] 0 0 0
> lista["second"] #return a filtered list by the condition
$second
[1] 0 0 0
Multidimensional Array and named indexes
> a<-array(1:24, dim=c(3,4,2))
> dim(a) #show dimensions
[1] 3 4 2
> a[,,2]
[,1] [,2] [,3] [,4]
[1,] 13 16 19 22
[2,] 14 17 20 23
[3,] 15 18 21 24
> a[1,,]
[,1] [,2]
[1,] 1 13
[2,] 4 16
[3,] 7 19
[4,] 10 22
> a[1,2,1]
[1] 4
> x<-matrix(1:10, ncol=5)
> dimnames(x)<-list(c("X","Y"),NULL)
[,1] [,2] [,3] [,4] [,5]
X 1 3 5 7 9
Y 2 4 6 8 10
> dimnames(x)[[2]]<-c("g","h","j","j","k")
g h j j k
X 1 3 5 7 9
Y 2 4 6 8 10
Summary of Data Structures
Linear Rectangular
Homogeneous Vectors Matrices
Heterogeneous Lists Data frames
Data frame
> X<-data.frame(id=1:4, sex=c("M","F","F","M"))
id sex
1 1 M
2 2 F
3 3 F
4 4 M
> X$age<-c(2.5,3,5,6.2)
id sex age
1 1 M 2.5
2 2 F 3.0
3 3 F 5.0
4 4 M 6.2
#X[X$age<3 | X$age>5, c("id","sex")]
> subset(X,subset=(age<3 | age>5), select=-age)
id sex
1 1 M
4 4 M #see also merge, attach
> summary(X)
id sex age
Min. :1.00 F:2 Min. :2.500
1st Qu.:1.75 M:2 1st Qu.:2.875
Median :2.50 Median :4.000
Mean :2.50 Mean :4.175
3rd Qu.:3.25 3rd Qu.:5.300
Max. :4.00 Max. :6.200

Mais conteúdo relacionado

Mais procurados

R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In RRsquared Academy
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factorskrishna singh
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply FunctionSakthi Dasans
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classificationYanchang Zhao
 
An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)Dataspora
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching moduleSander Timmer
 
RDataMining slides-time-series-analysis
RDataMining slides-time-series-analysisRDataMining slides-time-series-analysis
RDataMining slides-time-series-analysisYanchang Zhao
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in REshwar Sai
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RRsquared Academy
 
RDataMining slides-network-analysis-with-r
RDataMining slides-network-analysis-with-rRDataMining slides-network-analysis-with-r
RDataMining slides-network-analysis-with-rYanchang Zhao
 
Next Generation Programming in R
Next Generation Programming in RNext Generation Programming in R
Next Generation Programming in RFlorian Uhlitz
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RRsquared Academy
 
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data VisualizationSakthi Dasans
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data StructureSakthi Dasans
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In RRsquared Academy
 

Mais procurados (20)

R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
R language
R languageR language
R language
 
Language R
Language RLanguage R
Language R
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classification
 
An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
RDataMining slides-time-series-analysis
RDataMining slides-time-series-analysisRDataMining slides-time-series-analysis
RDataMining slides-time-series-analysis
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in R
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
 
RDataMining slides-network-analysis-with-r
RDataMining slides-network-analysis-with-rRDataMining slides-network-analysis-with-r
RDataMining slides-network-analysis-with-r
 
Next Generation Programming in R
Next Generation Programming in RNext Generation Programming in R
Next Generation Programming in R
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data Visualization
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In R
 

Destaque

R programming language: conceptual overview
R programming language: conceptual overviewR programming language: conceptual overview
R programming language: conceptual overviewMaxim Litvak
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformSyracuse University
 
R language tutorial
R language tutorialR language tutorial
R language tutorialDavid Chiu
 
A Brief History of Programming
A Brief History of ProgrammingA Brief History of Programming
A Brief History of Programmingjxyz
 
R Introduction
R IntroductionR Introduction
R Introductionschamber
 
Intro to RStudio
Intro to RStudioIntro to RStudio
Intro to RStudioegoodwintx
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming LanguagesSayanee Basu
 
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...Revolution Analytics
 
Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2izahn
 
R programming Basic & Advanced
R programming Basic & AdvancedR programming Basic & Advanced
R programming Basic & AdvancedSohom Ghosh
 
Bioinformatics
BioinformaticsBioinformatics
Bioinformaticsbiinoida
 
Operating Systems: Linux in Detail
Operating Systems: Linux in DetailOperating Systems: Linux in Detail
Operating Systems: Linux in DetailDamian T. Gordon
 

Destaque (20)

R programming language: conceptual overview
R programming language: conceptual overviewR programming language: conceptual overview
R programming language: conceptual overview
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics Platform
 
Class ppt intro to r
Class ppt intro to rClass ppt intro to r
Class ppt intro to r
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
 
Moodle for teachers
Moodle for teachersMoodle for teachers
Moodle for teachers
 
A Brief History of Programming
A Brief History of ProgrammingA Brief History of Programming
A Brief History of Programming
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Intro to RStudio
Intro to RStudioIntro to RStudio
Intro to RStudio
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming Languages
 
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
Big Data Predictive Analytics with Revolution R Enterprise (Gartner BI Summit...
 
Bioinformatics
BioinformaticsBioinformatics
Bioinformatics
 
Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2
 
R programming Basic & Advanced
R programming Basic & AdvancedR programming Basic & Advanced
R programming Basic & Advanced
 
Bioinformatics
BioinformaticsBioinformatics
Bioinformatics
 
R programming
R programmingR programming
R programming
 
Step By Step Guide to Learn R
Step By Step Guide to Learn RStep By Step Guide to Learn R
Step By Step Guide to Learn R
 
What Is Organic Farming
What Is Organic FarmingWhat Is Organic Farming
What Is Organic Farming
 
Organic farming
Organic farmingOrganic farming
Organic farming
 
Operating Systems: Linux in Detail
Operating Systems: Linux in DetailOperating Systems: Linux in Detail
Operating Systems: Linux in Detail
 

Semelhante a R programming language

Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.Dr. Volkan OBAN
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Dr. Volkan OBAN
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In RRsquared Academy
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with RYanchang Zhao
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environmentYogendra Chaubey
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Getting started with R when analysing GitHub commits
Getting started with R when analysing GitHub commitsGetting started with R when analysing GitHub commits
Getting started with R when analysing GitHub commitsBarbara Fusinska
 
Introduction to R
Introduction to RIntroduction to R
Introduction to RStacy Irwin
 

Semelhante a R programming language (20)

R Programming Homework Help
R Programming Homework HelpR Programming Homework Help
R Programming Homework Help
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
R and data mining
R and data miningR and data mining
R and data mining
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
R
RR
R
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
 
R for you
R for youR for you
R for you
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Getting started with R when analysing GitHub commits
Getting started with R when analysing GitHub commitsGetting started with R when analysing GitHub commits
Getting started with R when analysing GitHub commits
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 

Mais de Alberto Minetti

Gnutella Italian Printable
Gnutella Italian PrintableGnutella Italian Printable
Gnutella Italian PrintableAlberto Minetti
 
Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)Alberto Minetti
 
High Level Synthesis Using Esterel
High Level Synthesis Using EsterelHigh Level Synthesis Using Esterel
High Level Synthesis Using EsterelAlberto Minetti
 

Mais de Alberto Minetti (9)

Minetti master thesis
Minetti master thesisMinetti master thesis
Minetti master thesis
 
Index for meshes 2d
Index for meshes 2dIndex for meshes 2d
Index for meshes 2d
 
Index for meshes 3d
Index for meshes 3dIndex for meshes 3d
Index for meshes 3d
 
Gnutella Italian Printable
Gnutella Italian PrintableGnutella Italian Printable
Gnutella Italian Printable
 
Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)
 
Inferno Limbo Italian
Inferno Limbo ItalianInferno Limbo Italian
Inferno Limbo Italian
 
Telegraph Cq Italian
Telegraph Cq ItalianTelegraph Cq Italian
Telegraph Cq Italian
 
Telegraph Cq English
Telegraph Cq EnglishTelegraph Cq English
Telegraph Cq English
 
High Level Synthesis Using Esterel
High Level Synthesis Using EsterelHigh Level Synthesis Using Esterel
High Level Synthesis Using Esterel
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 

Último (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 

R programming language

  • 2. What is R? • Functional programming language • Matrix-based • Interpreted (written in C and Fortran) • Environment for statistical computing and graphics • Open source and GPL license • 6000+ packages in CRAN
  • 3. Why use R? • Matrix calculation • Data visualization (interactive too) • Statistic analysis (regression, time series, geo-spatial) • Data mining, classification, clustering • Analysis of genomic data • Machine learning
  • 4. Who uses R? • Oracle integrates R in its Big Data Appliance • IBM offers support for in-Hadoop execution of R • Data analysts for Google and Apple • 12° in TIOBE popularity index
  • 5. How to use R? • Command-line interface, autonomous script or graphical front-ends • Connection to any data source • Data analysis • Modeling and computation • Data visualization • Fitting models or displaying data
  • 6. R Studio IDE • licence AGPL 3 • Scripts • Workspace • Console • Images
  • 7. Reading and writing data • From/To plain text files • From/To Excel files • From/To Databases • From the Web > heisenberg <- read.csv(file="simple.csv",head=TRUE,sep=",") > write.csv(x=data, file="simple.csv") > library(gdata) > mydata = read.xls("mydata.xls") > write.xlsx(x=data, file="simple.csv«) > library(XLConnect) > wk = loadWorkbook("mydata.xls") > df = readWorksheet(wk,sheet="Sheet1") > library(RPostgreSQL) > con <- dbConnect(dbDriver("PostgreSQL"), dbname = "abc", user="postgres") > q <- dbGetQuery(con, "SELECT * FROM prices WHERE x > 0") > dbSendQuery(con, “INSERT INTO forecasts VALUE (10)") > fpe <- read.table("http://data.princeton.edu/wws509/datasets/effort.dat")
  • 8. Programming features • Flow control statements • while, repeat, break, continue, if, return • Exceptions, using try catch blocks • Functions • Default parameters • Positional or named arguments • Generic • Anonymous fibonacci <- function(n) { if(n<=2) return 1 fib <- numeric(n) fib[1:2] <- 1 for(i in 3:n) { fib[i] <- fib[i-1] + fib[i-2] } return (fib[n]) } arr <- function(a = 1, b = 2) { c(a, b) } > arr(b=6) [1] 1 6 f3 <- function(f) { f(3) } f3(function(x) {x*7}) `%my%` <- function(a,b) { return 2*a + 2 *b }
  • 9. Correlation mpg hp cyl Mazda RX4 21.0 110 6 Mazda RX4 Wag 21.0 110 6 Datsun 710 22.8 93 4 Hornet 4 Drive 21.4 110 6 Hornet Sportabout 18.7 175 8 Valiant 18.1 105 6 Duster 360 14.3 245 8 Merc 240D 24.4 62 4 Merc 230 22.8 95 4 Merc 280 19.2 123 6 Merc 280C 17.8 123 6 Merc 450SE 16.4 180 8 Merc 450SL 17.3 180 8 Merc 450SLC 15.2 180 8 Cadillac Fleetwood 10.4 205 8 Lincoln Continental 10.4 215 8 Chrysler Imperial 14.7 230 8 Fiat 128 32.4 66 4 Honda Civic 30.4 52 4 Toyota Corolla 33.9 65 4 Toyota Corona 21.5 97 4 Dodge Challenger 15.5 150 8 AMC Javelin 15.2 150 8 Camaro Z28 13.3 245 8 Pontiac Firebird 19.2 175 8 Fiat X1-9 27.3 66 4 Porsche 914-2 26.0 91 4 Lotus Europa 30.4 113 4 Ford Pantera L 15.8 264 8 Ferrari Dino 19.7 175 6 Maserati Bora 15.0 335 8 Volvo 142E 21.4 109 4 > mtcars2 <- subset(mtcars, select=c("mpg", "hp", "cyl")) > pairs(mtcars2)
  • 10. Auto-correlation > A <- read.table(“http://cdiac.ornl.gov/ftp/trends/co2/maunaloa.co2”) > X=t(A[1,]) > ts.plot(X) > acf(X)
  • 11. Plotting > x <- seq(-1.57,1.57,by=.001) > y <- (sqrt(abs(cos(x))) * cos(200*x) + sqrt(abs(x))-0.7) * (4-x * x)^0.01 > plot(0,0, type=‘n’, xlim=c(-2,+2),ylim=c(-1.6,+1.1)) > lines(x,y,col='pink') > spread <- seq(1, length(x), length.out=length(x)/10) > cols <- c('yellow','red','orange', 'purple') > text(x[spread],y[spread], label='love', col=sample(rep(cols, length.out=length(spread))), cex=1)
  • 12. Regression > library("MASS") > str(cats) 'data.frame': 144 obs. of 3 variables: $ Sex: Factor w/ 2 levels "F","M": 1 1 1 1 1 1 1 1 1 1 ... $ Bwt: num 2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ... $ Hwt: num 7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ... attach(cats) > lm.out <- lm(Hwt ~ Bwt) Call: lm(formula = Hwt ~ Bwt) Coefficients: (Intercept) Bwt -0.3567 4.0341 > plot(Hwt ~ Bwt, main="Kitty Cat Plot") > abline(lm.out, col="red")
  • 13. Data manipulation: discretisation > clinical.trial <- data.frame(patient = 1:100, age= rnorm(100, mean = 60, sd = 8), year.enroll = sample(paste("19", 85:99, sep = ""), 100, replace = TRUE)) > c1 <- cut(clinical.trial$age, breaks = 4) > table(c1) (41.1,50] (50,58.8] (58.8,67.6] (67.6,76.4] 9 34 41 16 > hist(clinical.trial$age, breaks=seq(40,100, by=10))
  • 14. Plots from my MSc thesis • Prices of energy in the Italian Power Exchange spot market • Forecast using a SARIMA model
  • 15. Performances • Good performances with built-in math functions • Possibility to monitor the memory usage • Possibility to offload data to an external DB to speed up large operations • Functions for big data sets • Parallel computation
  • 16. Credits • http://adv-r.had.co.nz/ • http://cran.r-project.org/ • http://simplystatistics.org/2013/02/15/interview-with-nick- chamandy-statistician-at-google/ • https://kaosktrl.wordpress.com/2010/02/04/r-lanalisi-delle-serie- storiche-partendo-da-copenaghen/
  • 17. Vector part 1 > x <- c(2,5,9.5,-3) #create a vector > x[2] #selects the second element [1] 5 > x[c(2,4)] #select the elements in position 2 and 4 [1] 5 -3 > x[-c(1,3)] #keep out the elements in position 1 and 3 [1] 5 -3 > x[x>0] #select only positive elements [1] 2.0 5.0 9.5 > x[!(x<=0)] #keep out the striclty not positve elements [1] 2.0 5.0 9.5 > x[x>0]-1 > x[x>0]+c(1,2,3) #sum element-wise [1] 1.0 4.0 8.5 [1] 3.0 7.0 11.0 > x[x>0][2] [1] 5
  • 18. Vector part 2 > which(x>0) #show the indexes that match the condition [1] 1 2 3 > which.max(x) > which.min(x) > length(x) [1] 4 [1] 3 [1] 4 > x<-1:10 > paste(1:5, c("A","B"), sep="") [1] 1 2 3 4 5 6 7 8 9 10 [1] "1A" "2B" "3A" "4B" "5A" > x1<-seq(1,1000, length=10) #vector from 1 to 1000 with step 10 [1] 1 112 223 334 445 556 667 778 889 1000 > x2<-rep(2,times=10) #repeat 2 10 times [1] 2 2 2 2 2 2 2 2 2 2 > rep(c(1,3),times=4) #repeat (1,3) 4 times [1] 1 3 1 3 1 3 1 3 > rep(c(1,9),c(3,1)) #repeat (1,9) 3 and 1 times respectively [1] 1 1 1 9 > length(c(x,x1,x2,3)) [1] 31 #see also sort, order, eigen
  • 19. Matrix part 1 > x<-matrix(1:10,ncol=5) #create [,1] [,2] [,3] [,4] [,5] [1,] 1 3 5 7 9 [2,] 2 4 6 8 10 > x[,1] #select the first column [1] 1 2 > x[,4:5] #select columns 4 and 5 [,1] [,2] [1,] 7 9 [2,] 8 10 > cbind(1:2,c(1,-2),c(0,9)) #combine vectors by columns/rows (rbind) [,1] [,2] [,3] [1,] 1 1 0 [2,] 2 -2 9 > x[2,]<-rep(2,5) [,1] [,2] [,3] [,4] [,5] [1,] 1 3 5 7 9 [2,] 2 2 2 2 2 > x[2,] #select the second row [1] 2 4 6 8 10 > x[,-c(2,4)] #select columns 1 3 5 [,1] [,2] [,3] [1,] 1 5 9 [2,] 2 6 10
  • 20. Matrix part 2 > X<-diag(1:3) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 2 0 [3,] 0 0 3 > solve(X) #the inverse of X [,1] [,2] [,3] [1,] 1 0.0 0.0000000 [2,] 0 0.5 0.0000000 [3,] 0 0.0 0.3333333 > X%*%solve(X)#....verify [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1
  • 21. List, can contain different object types > lista<-list(matrix(1:9,nrow=3),rep(0,3),c(‘good’,’bad’)) > length(lista) [1] 3 > lista[[3]] #third element [1] ‘good’ ‘bad’ > length(lista[[3]]) [1] 2 > lista[[2]]+2 #sum on the second item [1] 2 2 2 > lista[[1]][2,2] [1] 5 > names(lista)<-c(‘first’, ‘second’, ‘third’) #names for elements > lista$second #or lista[[second]] return a vector [1] 0 0 0 > lista["second"] #return a filtered list by the condition $second [1] 0 0 0
  • 22. Multidimensional Array and named indexes > a<-array(1:24, dim=c(3,4,2)) > dim(a) #show dimensions [1] 3 4 2 > a[,,2] [,1] [,2] [,3] [,4] [1,] 13 16 19 22 [2,] 14 17 20 23 [3,] 15 18 21 24 > a[1,,] [,1] [,2] [1,] 1 13 [2,] 4 16 [3,] 7 19 [4,] 10 22 > a[1,2,1] [1] 4 > x<-matrix(1:10, ncol=5) > dimnames(x)<-list(c("X","Y"),NULL) [,1] [,2] [,3] [,4] [,5] X 1 3 5 7 9 Y 2 4 6 8 10 > dimnames(x)[[2]]<-c("g","h","j","j","k") g h j j k X 1 3 5 7 9 Y 2 4 6 8 10 Summary of Data Structures Linear Rectangular Homogeneous Vectors Matrices Heterogeneous Lists Data frames
  • 23. Data frame > X<-data.frame(id=1:4, sex=c("M","F","F","M")) id sex 1 1 M 2 2 F 3 3 F 4 4 M > X$age<-c(2.5,3,5,6.2) id sex age 1 1 M 2.5 2 2 F 3.0 3 3 F 5.0 4 4 M 6.2 #X[X$age<3 | X$age>5, c("id","sex")] > subset(X,subset=(age<3 | age>5), select=-age) id sex 1 1 M 4 4 M #see also merge, attach > summary(X) id sex age Min. :1.00 F:2 Min. :2.500 1st Qu.:1.75 M:2 1st Qu.:2.875 Median :2.50 Median :4.000 Mean :2.50 Mean :4.175 3rd Qu.:3.25 3rd Qu.:5.300 Max. :4.00 Max. :6.200

Notas do Editor

  1. R's data structures include vectors, matrices, multidimensional arrays, lists and data frames (similar to tables in a relational database). A scalar is represented as a vector with length one. It’s interpreted and its packages are mainly written using R, C and Fortran. R is freely available under the GPL, and pre-compiled binary versions are provided for various operating systems. The R community is very active in terms of packages for specific functions or specific areas of study.
  2. R can act as a matrix-calculation toolbox with performances comparable to GNU Octave or MATLAB. Another strength of R is static graphics, which can produce publication-quality graphs, including mathematical symbols. Dynamic and interactive graphics are available through additional packages. R's system includes objects for: regression models, time-series and geo-spatial coordinates, techniques for linear and nonlinear modeling, classical statistical tests, classification, clustering, and others. R is easily extensible through functions and extensions.
  3. Polls and surveys of data miners show that R's popularity has increased substantially in recent years.
  4. R is an interpreted language; users typically access it through a command-line interpreter; there are also several graphical front-ends for it. …
  5. The IDE I used is very similar to MatLam with the following four sections: one for the scripts, one for the current workspace where the objects and the matriices are easlily accessible, one for the console to compute analysis on the fly, one for the generated images
  6. R has the same capability of common procedural languages, to control the flow you can use instructions like while, repeat, if, and functions. R allows to handle exceptions using try catch blocks. Functions have default parameters in the definition, you can call a function using positional or named arguments. A generic function acts differently depending on the type of arguments passed to it. So, the generic function dispatches the implementation specific to that type of object. For example, R has a generic print function that can print almost every type of object in R with a simple print(objectname) syntax.
  7. One line methods for: correlation, plotting, regression,
  8. The syntax to caltulate the regression