Introduction to R and Statistics
-
Upload
martha-potter -
Category
Documents
-
view
21 -
download
0
description
Transcript of Introduction to R and Statistics
![Page 1: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/1.jpg)
Introduction to R and StatisticsThomas INGICCO
G. Courbet, Le désespéré (Autoportrait)G. Courbet, The desperate man (Self-portrait)
![Page 2: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/2.jpg)
R is a freeware…
![Page 3: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/3.jpg)
… but before all it is a language with its own grammar made of:
![Page 4: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/4.jpg)
… but before all it is a language with its own grammar made of:
To create an object which will contain data or informations, we use "<-" :aa <- NULLaa <- "A sentence"bb <- 10:34cc <- matrix(10:34, nc=5, nr=5)
To see the content of the object, we type its name:aa
Hash symbol (#) allows you to comment your script:aa # This is a comment
Semicolon allows you to separate the commands on the same line:aa ; bb ; cc # We look at the content of the three objects
R is case sensitiveaa Aa # R being a language, when you make a mistake, it tells you
Spaces are not importantbbb<-10 : 34
![Page 5: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/5.jpg)
… but R is also a calculator:
25/5
5^2
25^0.5sqrt(25) # This is a function
sqrt
?sqrthelp(sqrt)
![Page 6: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/6.jpg)
… but R is also a calculator:
25/5
5^2
25^0.5sqrt(25) # This is a function
sqrt
?sqrthelp(sqrt)
sqrt(sum(bb)) # Functions are matriochkas
![Page 7: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/7.jpg)
… but R is also a calculator:
25/5
5^2
25^0.5sqrt(25) # This is a function
sqrt
?sqrthelp(sqrt)
sqrt(sum(bb)) # Functions are matriochkas
bb[-3]bb+bbbb+bb[-3]bb+cc
![Page 8: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/8.jpg)
… but before all it is a language with its own grammar made of:
![Page 9: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/9.jpg)
Modes – nature of your data- Numeric – numbers (51, 32, 47mm)- Character – chain of characters (« y », « a+b+c »)- Factor – qualitative values (« Red », « Orange »)- Logical – specific attributes (TRUE, FALSE, NA)
Special arguments- NA – Not Available, absence of data- NULL – Empty object- TRUE or T – Logical argument- FALSE or F– Logical argument
… but before all it is a language with its own grammar made of:
![Page 10: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/10.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
ls() # Check the list of the created objects
# Vectoris.vector(bb)
![Page 11: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/11.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
# Matrixclass(cc)cc <- matrix(10:34, nc=5, nr=5) # Remember
ccc <- c(10:34)ccc
![Page 12: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/12.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
# Matrixclass(cc)cc <- matrix(10:34, nc=5, nr=5) # Remember
ccc <- c(10:34)ccc
is.vector(ccc)dim(ccc)<-c(5,5)ccc
![Page 13: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/13.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
# Matrixclass(cc)cc <- matrix(10:34, nc=5, nr=5) # Remember
ccc <- c(10:34)ccc
is.vector(ccc)dim(ccc)<-c(5,5)cccis.matrix(ccc)
![Page 14: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/14.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
# Matrixclass(cc)cc <- matrix(10:34, nc=5, nr=5) # Remember
ccc <- c(10:34)ccc
is.vector(ccc)dim(ccc)<-c(5,5)cccis.matrix(ccc)
matrix(1:6, 3, 2)matrix(1:6, 3, 2, byrow=T)
![Page 15: Introduction to R and Statistics](https://reader030.fdocuments.in/reader030/viewer/2022033100/5681351f550346895d9c8214/html5/thumbnails/15.jpg)
Classes – how you present your data- Vector – series of values of 1 dimension- Matrix – series of values of 2 dimensions- Arrays – series of values of n dimensions- Data Frame – series of values in columns- List – series of objects- Table – Contingency table
… but before all it is a language with its own grammar made of:
# Data.framedd<-read.table("K:/Cours/Philippines/Statistics-210/Lecture-4/Ceramics.txt", header=TRUE)
# Opening Data; return is possible in a function; a function has arguments
class(dd)
dd$Typedd[,9]dd[3,8:11]