R ¡
A ¡Personalized ¡Introduc3on ¡ ¡
Debapriyo Majumdar Data Mining – Fall 2014 Indian Statistical Institute Kolkata
August 18, 2014
R A Personalized Introduc3on Debapriyo Majumdar Data Mining - - PowerPoint PPT Presentation
R A Personalized Introduc3on Debapriyo Majumdar Data Mining Fall 2014 Indian Statistical Institute Kolkata August 18, 2014 About R A suite of software tools for Data manipulation
Debapriyo Majumdar Data Mining – Fall 2014 Indian Statistical Institute Kolkata
August 18, 2014
2 ¡
§ Arithmetic
> 2+2 [1] 4
§ Assign variables
> x <- 2 > y <- 5 > z <- 2 * x + 3 * y > z [1] 19
§ The created objects are now stored in the workspace. List them
> ls() [1] "x" "y" "z”
§ Also, we can remove them
> rm(x) > ls() [1] "y" "z”
4 ¡
> x <- c(2,3,1,5,7,2,5,8,3,2,0,3,2,6,7,3,1,3,5,8,4) > summary(x)
0.00 2.00 3.00 3.81 5.00 8.00
> x[1] [1] 2 > x[3:6] [1] 1 5 7 2
> x[-(2:4)] [1] 2 7 2 5 8 3 2 0 3 2 6 7 3 1 3 5 8 4
6 ¡
7 ¡
> A + 2* A
[1,] 9 24 [2,] 15 6 [3,] 6 3
> A %*% B
[1,] 49 70 14 [2,] 25 26 12 [3,] 11 12 5
8 ¡
> solve(X)
> var(X) > cov(X)
> z <- function(x,y) 3*x + 4*y > z(2,3) [1] 18
> z <- function(x,y) {
}
> source("/Users/deb/…/R/xTest.R")
> “%LL%” <- function(x,y) { 3*x + 4*y } > 5 %LL% 3
– The first line of the file should have a name for each variable in the data frame – Each additional line of the file has as its first item a row label and the values for each variable Age Income.K Owns.House 01 25 8 No 02 33 5 No 03 30 130 Yes 04 45 50 Yes 05 65 5 No 06 75 7 Yes
> plot(H[1:2])
– Let us select a subset of the data
> H[which(H$Owns.House=='Yes'),] Age Income.K Owns.House 03 30 130 Yes 04 45 50 Yes 06 75 7 Yes 07 28 200 Yes 08 35 90 Yes 10 55 102 Yes … … … …
30 40 50 60 70 80 50 100 150 200 Age Income.K
> HYes <- H[which(H $Owns.House=='Yes'),]
col='blue')
col='red') New ¡observa3on ¡(black) ¡
14 ¡