#this is where we write code 

ls()
## character(0)
rm("x")
## Warning in rm("x"): object 'x' not found
rm(list=ls())
ls()
## character(0)
data(iris)
head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
tail(iris)
##     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
## 145          6.7         3.3          5.7         2.5 virginica
## 146          6.7         3.0          5.2         2.3 virginica
## 147          6.3         2.5          5.0         1.9 virginica
## 148          6.5         3.0          5.2         2.0 virginica
## 149          6.2         3.4          5.4         2.3 virginica
## 150          5.9         3.0          5.1         1.8 virginica
names(iris)
## [1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width" 
## [5] "Species"
iris$Sepal.Length2=32*iris$Sepal.Length

attach(iris)

mean(Sepal.Length2)
## [1] 186.9867
for (i in 1:125) {print(i)}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
## [1] 11
## [1] 12
## [1] 13
## [1] 14
## [1] 15
## [1] 16
## [1] 17
## [1] 18
## [1] 19
## [1] 20
## [1] 21
## [1] 22
## [1] 23
## [1] 24
## [1] 25
## [1] 26
## [1] 27
## [1] 28
## [1] 29
## [1] 30
## [1] 31
## [1] 32
## [1] 33
## [1] 34
## [1] 35
## [1] 36
## [1] 37
## [1] 38
## [1] 39
## [1] 40
## [1] 41
## [1] 42
## [1] 43
## [1] 44
## [1] 45
## [1] 46
## [1] 47
## [1] 48
## [1] 49
## [1] 50
## [1] 51
## [1] 52
## [1] 53
## [1] 54
## [1] 55
## [1] 56
## [1] 57
## [1] 58
## [1] 59
## [1] 60
## [1] 61
## [1] 62
## [1] 63
## [1] 64
## [1] 65
## [1] 66
## [1] 67
## [1] 68
## [1] 69
## [1] 70
## [1] 71
## [1] 72
## [1] 73
## [1] 74
## [1] 75
## [1] 76
## [1] 77
## [1] 78
## [1] 79
## [1] 80
## [1] 81
## [1] 82
## [1] 83
## [1] 84
## [1] 85
## [1] 86
## [1] 87
## [1] 88
## [1] 89
## [1] 90
## [1] 91
## [1] 92
## [1] 93
## [1] 94
## [1] 95
## [1] 96
## [1] 97
## [1] 98
## [1] 99
## [1] 100
## [1] 101
## [1] 102
## [1] 103
## [1] 104
## [1] 105
## [1] 106
## [1] 107
## [1] 108
## [1] 109
## [1] 110
## [1] 111
## [1] 112
## [1] 113
## [1] 114
## [1] 115
## [1] 116
## [1] 117
## [1] 118
## [1] 119
## [1] 120
## [1] 121
## [1] 122
## [1] 123
## [1] 124
## [1] 125
for (i in 1:5) {
  y=rnorm(i,10,5)
  print(y)
  }
## [1] 11.71084
## [1] 14.441111  5.545809
## [1]  6.763619 15.847062 12.994043
## [1] 12.466964  9.621464  4.663421 12.291968
## [1] 11.760415 -1.408712 12.997844 14.859923 17.269609
sd(Sepal.Length2)
## [1] 26.49812
sd(Sepal.Length)
## [1] 0.8280661
yourname=function(x){
  y=x^3+log(32*x)-21*x+12
}
print(yourname(10))
## [1] 807.7683
yourname=function(x){
  y=x^3+12
}
print(yourname(10))
## [1] 1012
for (i in 1:25) {print(yourname(i))}
## [1] 13
## [1] 20
## [1] 39
## [1] 76
## [1] 137
## [1] 228
## [1] 355
## [1] 524
## [1] 741
## [1] 1012
## [1] 1343
## [1] 1740
## [1] 2209
## [1] 2756
## [1] 3387
## [1] 4108
## [1] 4925
## [1] 5844
## [1] 6871
## [1] 8012
## [1] 9273
## [1] 10660
## [1] 12179
## [1] 13836
## [1] 15637
dim(iris)
## [1] 150   6
str(iris)
## 'data.frame':    150 obs. of  6 variables:
##  $ Sepal.Length : num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width  : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length : num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width  : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species      : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Sepal.Length2: num  163 157 150 147 160 ...
getwd()
## [1] "C:/Users/Dell/Documents/R"
setwd("C:/Users/Dell/Desktop")
dir()
##  [1] "16508797_10155115909410362_414170078812994931_n.jpg"
##  [2] "AJAY.xps"                                           
##  [3] "BigDiamonds.csv"                                    
##  [4] "BLOOD REPORT.pdf"                                   
##  [5] "CAM- Ajay Ohri.pdf"                                 
##  [6] "clustersas.html"                                    
##  [7] "desktop.ini"                                        
##  [8] "Dropbox.lnk"                                        
##  [9] "DVD.csv"                                            
## [10] "GermanCredit.csv"                                   
## [11] "Git Shell.lnk"                                      
## [12] "GitHub.appref-ms"                                   
## [13] "GoToMeeting.lnk"                                    
## [14] "groceries.csv"                                      
## [15] "IMS proschool"                                      
## [16] "logistic regression - script for ppt.R"             
## [17] "Program 1-results.rtf"                              
## [18] "Rdatasets"                                          
## [19] "Results_ Modeling and Forecasting.html"             
## [20] "Results_ Program 5.sas.html"                        
## [21] "Results_ Time Series Exploration.ctk.html"          
## [22] "sas-university-edition-107140.pdf"                  
## [23] "test"
dir(pattern = ".csv")
## [1] "BigDiamonds.csv"  "DVD.csv"          "GermanCredit.csv"
## [4] "groceries.csv"
BigDiamonds2=read.csv("BigDiamonds.csv",header=T)

head(BigDiamonds2)
##   X carat    cut color clarity table depth cert       measurements price
## 1 1  0.25 V.Good     K      I1    59  63.7  GIA 3.96 x 3.95 x 2.52    NA
## 2 2  0.23   Good     G      I1    61  58.1  GIA 4.00 x 4.05 x 2.30    NA
## 3 3  0.34   Good     J      I2    58  58.7  GIA 4.56 x 4.53 x 2.67    NA
## 4 4  0.21 V.Good     D      I1    60  60.6  GIA 3.80 x 3.82 x 2.31    NA
## 5 5  0.31 V.Good     K      I1    59  62.2  EGL 4.35 x 4.26 x 2.68    NA
## 6 6  0.20   Good     G     SI2    60  64.4  GIA 3.74 x 3.67 x 2.38    NA
##      x    y    z
## 1 3.96 3.95 2.52
## 2 4.00 4.05 2.30
## 3 4.56 4.53 2.67
## 4 3.80 3.82 2.31
## 5 4.35 4.26 2.68
## 6 3.74 3.67 2.38
str(BigDiamonds2)
## 'data.frame':    598024 obs. of  13 variables:
##  $ X           : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ carat       : num  0.25 0.23 0.34 0.21 0.31 0.2 0.2 0.22 0.23 0.2 ...
##  $ cut         : Factor w/ 3 levels "Good","Ideal",..: 3 1 1 3 3 1 1 3 3 1 ...
##  $ color       : Factor w/ 9 levels "D","E","F","G",..: 8 4 7 1 8 4 4 1 8 3 ...
##  $ clarity     : Factor w/ 9 levels "I1","I2","IF",..: 1 1 2 1 1 5 5 1 5 4 ...
##  $ table       : num  59 61 58 60 59 60 63 61 57.5 65 ...
##  $ depth       : num  63.7 58.1 58.7 60.6 62.2 64.4 62.6 59.2 63.6 54.9 ...
##  $ cert        : Factor w/ 9 levels "AGS","EGL","EGL Intl.",..: 6 6 6 6 2 6 6 6 8 6 ...
##  $ measurements: Factor w/ 241453 levels "","  3.99  x   3.95  x   2.44",..: 19960 21917 48457 15701 37341 14661 14400 19642 17115 16177 ...
##  $ price       : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ x           : num  3.96 4 4.56 3.8 4.35 3.74 3.72 3.95 3.87 3.83 ...
##  $ y           : num  3.95 4.05 4.53 3.82 4.26 3.67 3.65 3.97 3.9 4 ...
##  $ z           : num  2.52 2.3 2.67 2.31 2.68 2.38 2.31 2.34 2.47 2.14 ...
head(BigDiamonds2)
##   X carat    cut color clarity table depth cert       measurements price
## 1 1  0.25 V.Good     K      I1    59  63.7  GIA 3.96 x 3.95 x 2.52    NA
## 2 2  0.23   Good     G      I1    61  58.1  GIA 4.00 x 4.05 x 2.30    NA
## 3 3  0.34   Good     J      I2    58  58.7  GIA 4.56 x 4.53 x 2.67    NA
## 4 4  0.21 V.Good     D      I1    60  60.6  GIA 3.80 x 3.82 x 2.31    NA
## 5 5  0.31 V.Good     K      I1    59  62.2  EGL 4.35 x 4.26 x 2.68    NA
## 6 6  0.20   Good     G     SI2    60  64.4  GIA 3.74 x 3.67 x 2.38    NA
##      x    y    z
## 1 3.96 3.95 2.52
## 2 4.00 4.05 2.30
## 3 4.56 4.53 2.67
## 4 3.80 3.82 2.31
## 5 4.35 4.26 2.68
## 6 3.74 3.67 2.38
str(BigDiamonds2)
## 'data.frame':    598024 obs. of  13 variables:
##  $ X           : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ carat       : num  0.25 0.23 0.34 0.21 0.31 0.2 0.2 0.22 0.23 0.2 ...
##  $ cut         : Factor w/ 3 levels "Good","Ideal",..: 3 1 1 3 3 1 1 3 3 1 ...
##  $ color       : Factor w/ 9 levels "D","E","F","G",..: 8 4 7 1 8 4 4 1 8 3 ...
##  $ clarity     : Factor w/ 9 levels "I1","I2","IF",..: 1 1 2 1 1 5 5 1 5 4 ...
##  $ table       : num  59 61 58 60 59 60 63 61 57.5 65 ...
##  $ depth       : num  63.7 58.1 58.7 60.6 62.2 64.4 62.6 59.2 63.6 54.9 ...
##  $ cert        : Factor w/ 9 levels "AGS","EGL","EGL Intl.",..: 6 6 6 6 2 6 6 6 8 6 ...
##  $ measurements: Factor w/ 241453 levels "","  3.99  x   3.95  x   2.44",..: 19960 21917 48457 15701 37341 14661 14400 19642 17115 16177 ...
##  $ price       : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ x           : num  3.96 4 4.56 3.8 4.35 3.74 3.72 3.95 3.87 3.83 ...
##  $ y           : num  3.95 4.05 4.53 3.82 4.26 3.67 3.65 3.97 3.9 4 ...
##  $ z           : num  2.52 2.3 2.67 2.31 2.68 2.38 2.31 2.34 2.47 2.14 ...
#install.packages("XML")
library(XML)
url="http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;team=6;template=results;type=batting"
#Note I can also break the url string and use paste command to modify this url with parameters
tables=readHTMLTable(url)
ajay=tables$"Overall figures"
ajay
##             Player      Span Mat Inns NO  Runs   HS   Ave 100 50  0 
## 1     SR Tendulkar 1989-2013 200  329 33 15921 248* 53.78  51 68 14 
## 2         R Dravid 1996-2012 163  284 32 13265  270 52.63  36 63  7 
## 3      SM Gavaskar 1971-1987 125  214 16 10122 236* 51.12  34 45 12 
## 4       VVS Laxman 1996-2012 134  225 34  8781  281 45.97  17 56 14 
## 5         V Sehwag 2001-2013 103  178  6  8503  319 49.43  23 31 16 
## 6       SC Ganguly 1996-2008 113  188 17  7212  239 42.17  16 35 13 
## 7    DB Vengsarkar 1976-1992 116  185 22  6868  166 42.13  17 35 15 
## 8     M Azharuddin 1984-2000  99  147  9  6215  199 45.03  22 21  5 
## 9     GR Viswanath 1969-1983  91  155 10  6080  222 41.93  14 35 10 
## 10     N Kapil Dev 1978-1994 131  184 15  5248  163 31.05   8 27 16 
## 11        MS Dhoni 2005-2014  90  144 16  4876  224 38.09   6 33 10 
## 12      M Amarnath 1969-1988  69  113 10  4378  138 42.50  11 24 12 
## 13         V Kohli 2011-2017  54   91  7  4320  235 51.42  16 14  4 
## 14       G Gambhir 2004-2016  58  104  5  4154  206 41.95   9 22  7 
## 15      RJ Shastri 1981-1992  80  121 14  3830  206 35.79  11 12  9 
## 16      PR Umrigar 1948-1962  59   94  8  3631  223 42.22  12 14  5 
## 17       CA Pujara 2010-2017  44   73  6  3339 206* 49.83  10 12  2 
## 18         M Vijay 2008-2017  48   81  1  3288  167 41.10   9 14  5 
## 19    VL Manjrekar 1951-1965  55   92 10  3208 189* 39.12   7 15 11 
## 20        NS Sidhu 1983-1999  51   78  2  3202  201 42.13   9 15  9 
## 21        CG Borde 1958-1969  55   97 11  3061 177* 35.59   5 18 13 
## 22     MAK Pataudi 1961-1975  46   83  3  2793 203* 34.91   6 16  7 
## 23     SMH Kirmani 1976-1986  88  124 22  2759  102 27.04   2 12  7 
## 24     FM Engineer 1961-1975  46   87  3  2611  121 31.08   2 16  7 
## 25        A Kumble 1990-2008 132  173 32  2506 110* 17.77   1  5 17 
## 26           P Roy 1951-1960  43   79  4  2442  173 32.56   5  9 14 
## 27       AM Rahane 2013-2017  33   56  8  2317  188 48.27   8  9  4 
## 28 Harbhajan Singh 1998-2015 103  145 23  2224  115 18.22   2  9 19 
## 29       VS Hazare 1946-1953  30   52  6  2192 164* 47.65   7  9  4 
## 30      AL Wadekar 1966-1974  37   71  3  2113  143 31.07   1 14  7 
## 31       MH Mankad 1946-1959  44   72  5  2109  231 31.47   5  6  7 
## 32     CPS Chauhan 1969-1981  40   68  2  2084   97 31.57   0 16  6 
## 33     K Srikkanth 1981-1992  43   72  3  2062  123 29.88   2 12  7 
## 34     ML Jaisimha 1959-1971  39   71  4  2056  129 30.68   3 12  9 
## 35    SV Manjrekar 1987-1996  37   61  6  2043  218 37.14   4  9  3 
## 36     DN Sardesai 1961-1972  30   55  4  2001  212 39.23   5  9  4 
## 37      AD Gaekwad 1974-1985  40   70  4  1985  201 30.07   2 10  4 
## 38        W Jaffer 2000-2008  31   58  1  1944  212 34.10   5 11  6 
## 39    Yuvraj Singh 2003-2012  40   62  6  1900  169 33.92   3 11  7 
## 40        R Ashwin 2011-2017  45   62 10  1816  124 34.92   4 10  3 
## 41   NJ Contractor 1955-1962  31   52  1  1611  108 31.58   1 11  2 
## 42  Yashpal Sharma 1979-1983  37   59 11  1606  140 33.45   2  9  4 
## 43     M Prabhakar 1984-1995  39   58  9  1600  120 32.65   1  9  3 
## 44        SM Patil 1980-1984  29   47  4  1588  174 36.93   4  7  4 
## 45        S Dhawan 2013-2016  23   39  1  1464  187 38.52   4  3  4 
## 46       NR Mongia 1994-2001  44   68  8  1442  152 24.03   1  6  6 
## 47     RG Nadkarni 1955-1968  41   67 12  1414 122* 25.70   1  7  6 
## 48        S Ramesh 1999-2001  19   37  1  1367  143 37.97   2  8  3 
## 49          SS Das 2000-2002  23   40  2  1326  110 34.89   2  9  3 
## 50         KS More 1986-1993  49   64 14  1285   73 25.70   0  7  7
str(ajay)
## 'data.frame':    50 obs. of  12 variables:
##  $ Player: Factor w/ 50 levels "A Kumble","AD Gaekwad",..: 40 31 37 47 44 36 8 17 12 24 ...
##  $ Span  : Factor w/ 46 levels "1946-1953","1946-1959",..: 29 33 16 33 38 32 19 26 14 20 ...
##  $ Mat   : Factor w/ 36 levels "103","113","116",..: 10 8 4 7 1 2 3 36 35 5 ...
##  $ Inns  : Factor w/ 44 levels "104","113","121",..: 17 16 14 15 10 13 12 7 8 11 ...
##  $ NO    : Factor w/ 21 levels "1","10","11",..: 14 13 7 15 18 8 10 21 2 6 ...
##  $ Runs  : Factor w/ 50 levels "10122","1285",..: 10 4 1 50 49 48 47 46 45 44 ...
##  $ HS    : Factor w/ 46 levels "102","108","110",..: 41 42 39 43 44 40 18 27 34 16 ...
##  $ Ave   : Factor w/ 48 levels "17.77","18.22",..: 48 47 45 40 43 36 35 39 33 9 ...
##  $ 100   : Factor w/ 21 levels "0","1","10","11",..: 17 14 13 8 11 7 8 10 6 20 ...
##  $ 50    : Factor w/ 24 levels "10","11","12",..: 21 20 16 18 13 15 15 8 15 11 ...
##  $ 0     : Factor w/ 16 levels "10","11","12",..: 5 15 3 5 7 4 6 13 1 7 ...
##  $       : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
ajay$Runs=as.numeric(paste(ajay$Runs))
summary(ajay$Runs)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1285    1954    2474    3723    4278   15920
tables
## $`NULL`
##   View overall figures\n[change view]
## 1                  Primary team India
## 2 Ordered by runs scored (descending)
## 
## $`NULL`
## NULL
## 
## $`Overall figures`
##             Player      Span Mat Inns NO  Runs   HS   Ave 100 50  0 
## 1     SR Tendulkar 1989-2013 200  329 33 15921 248* 53.78  51 68 14 
## 2         R Dravid 1996-2012 163  284 32 13265  270 52.63  36 63  7 
## 3      SM Gavaskar 1971-1987 125  214 16 10122 236* 51.12  34 45 12 
## 4       VVS Laxman 1996-2012 134  225 34  8781  281 45.97  17 56 14 
## 5         V Sehwag 2001-2013 103  178  6  8503  319 49.43  23 31 16 
## 6       SC Ganguly 1996-2008 113  188 17  7212  239 42.17  16 35 13 
## 7    DB Vengsarkar 1976-1992 116  185 22  6868  166 42.13  17 35 15 
## 8     M Azharuddin 1984-2000  99  147  9  6215  199 45.03  22 21  5 
## 9     GR Viswanath 1969-1983  91  155 10  6080  222 41.93  14 35 10 
## 10     N Kapil Dev 1978-1994 131  184 15  5248  163 31.05   8 27 16 
## 11        MS Dhoni 2005-2014  90  144 16  4876  224 38.09   6 33 10 
## 12      M Amarnath 1969-1988  69  113 10  4378  138 42.50  11 24 12 
## 13         V Kohli 2011-2017  54   91  7  4320  235 51.42  16 14  4 
## 14       G Gambhir 2004-2016  58  104  5  4154  206 41.95   9 22  7 
## 15      RJ Shastri 1981-1992  80  121 14  3830  206 35.79  11 12  9 
## 16      PR Umrigar 1948-1962  59   94  8  3631  223 42.22  12 14  5 
## 17       CA Pujara 2010-2017  44   73  6  3339 206* 49.83  10 12  2 
## 18         M Vijay 2008-2017  48   81  1  3288  167 41.10   9 14  5 
## 19    VL Manjrekar 1951-1965  55   92 10  3208 189* 39.12   7 15 11 
## 20        NS Sidhu 1983-1999  51   78  2  3202  201 42.13   9 15  9 
## 21        CG Borde 1958-1969  55   97 11  3061 177* 35.59   5 18 13 
## 22     MAK Pataudi 1961-1975  46   83  3  2793 203* 34.91   6 16  7 
## 23     SMH Kirmani 1976-1986  88  124 22  2759  102 27.04   2 12  7 
## 24     FM Engineer 1961-1975  46   87  3  2611  121 31.08   2 16  7 
## 25        A Kumble 1990-2008 132  173 32  2506 110* 17.77   1  5 17 
## 26           P Roy 1951-1960  43   79  4  2442  173 32.56   5  9 14 
## 27       AM Rahane 2013-2017  33   56  8  2317  188 48.27   8  9  4 
## 28 Harbhajan Singh 1998-2015 103  145 23  2224  115 18.22   2  9 19 
## 29       VS Hazare 1946-1953  30   52  6  2192 164* 47.65   7  9  4 
## 30      AL Wadekar 1966-1974  37   71  3  2113  143 31.07   1 14  7 
## 31       MH Mankad 1946-1959  44   72  5  2109  231 31.47   5  6  7 
## 32     CPS Chauhan 1969-1981  40   68  2  2084   97 31.57   0 16  6 
## 33     K Srikkanth 1981-1992  43   72  3  2062  123 29.88   2 12  7 
## 34     ML Jaisimha 1959-1971  39   71  4  2056  129 30.68   3 12  9 
## 35    SV Manjrekar 1987-1996  37   61  6  2043  218 37.14   4  9  3 
## 36     DN Sardesai 1961-1972  30   55  4  2001  212 39.23   5  9  4 
## 37      AD Gaekwad 1974-1985  40   70  4  1985  201 30.07   2 10  4 
## 38        W Jaffer 2000-2008  31   58  1  1944  212 34.10   5 11  6 
## 39    Yuvraj Singh 2003-2012  40   62  6  1900  169 33.92   3 11  7 
## 40        R Ashwin 2011-2017  45   62 10  1816  124 34.92   4 10  3 
## 41   NJ Contractor 1955-1962  31   52  1  1611  108 31.58   1 11  2 
## 42  Yashpal Sharma 1979-1983  37   59 11  1606  140 33.45   2  9  4 
## 43     M Prabhakar 1984-1995  39   58  9  1600  120 32.65   1  9  3 
## 44        SM Patil 1980-1984  29   47  4  1588  174 36.93   4  7  4 
## 45        S Dhawan 2013-2016  23   39  1  1464  187 38.52   4  3  4 
## 46       NR Mongia 1994-2001  44   68  8  1442  152 24.03   1  6  6 
## 47     RG Nadkarni 1955-1968  41   67 12  1414 122* 25.70   1  7  6 
## 48        S Ramesh 1999-2001  19   37  1  1367  143 37.97   2  8  3 
## 49          SS Das 2000-2002  23   40  2  1326  110 34.89   2  9  3 
## 50         KS More 1986-1993  49   64 14  1285   73 25.70   0  7  7 
## 
## $`NULL`
##           V1 V2 V3
## 1 Go to page      
## 
## $`NULL`
## NULL
## 
## $`NULL`
##                                                                                                                     Statsguru includes the following current or recent Test matches:
## 1 India v Bangladesh at Hyderabad (Deccan), Only Test, Feb 9-13, 2017\n[Test # 2249 - Live]\n    » India 356/3 (90.0 ov, V Kohli 111*, AM Rahane 45*, Shakib Al Hasan 0/45) - Stumps
## 2                                                                                                 New Zealand v Bangladesh at Christchurch, 2nd Test, Jan 20-23, 2017\n[Test # 2248]
## 3                                                                                                   New Zealand v Bangladesh at Wellington, 1st Test, Jan 12-16, 2017\n[Test # 2246]
## 
## $`NULL`
##   V1   V2
## 1        
## 2        
## 3    <NA>
## 
## $`NULL`
## NULL
summary(BigDiamonds2)
##        X              carat           cut             color      
##  Min.   :     1   Min.   :0.200   Good  : 59680   G      :96204  
##  1st Qu.:149507   1st Qu.:0.500   Ideal :369448   F      :93573  
##  Median :299013   Median :0.900   V.Good:168896   E      :93483  
##  Mean   :299013   Mean   :1.071                   H      :86619  
##  3rd Qu.:448518   3rd Qu.:1.500                   D      :73630  
##  Max.   :598024   Max.   :9.250                   I      :70282  
##                                                   (Other):84233  
##     clarity           table           depth               cert       
##  SI1    :116631   Min.   : 0.00   Min.   : 0.00   GIA       :463555  
##  VS2    :111082   1st Qu.:56.00   1st Qu.:61.00   IGI       : 43667  
##  SI2    :104300   Median :58.00   Median :62.10   EGL       : 33814  
##  VS1    : 97730   Mean   :57.63   Mean   :61.06   EGL USA   : 16079  
##  VVS2   : 65500   3rd Qu.:59.00   3rd Qu.:62.70   EGL Intl. : 11447  
##  VVS1   : 54798   Max.   :75.90   Max.   :81.30   EGL ISRAEL: 11301  
##  (Other): 47983                                   (Other)   : 18161  
##                  measurements        price             x         
##  0.00  x  0.00  x  0.00:   425   Min.   :  300   Min.   : 0.150  
##  0.00 x 0.00 x 0.00    :   222   1st Qu.: 1220   1st Qu.: 4.740  
##  4.3 x 4.27 x 2.67     :    97   Median : 3503   Median : 5.780  
##  4.31 x 4.29 x 2.68    :    87   Mean   : 8753   Mean   : 5.991  
##  4.29 x 4.26 x 2.67    :    86   3rd Qu.:11174   3rd Qu.: 6.970  
##  4.3 x 4.28 x 2.67     :    84   Max.   :99990   Max.   :13.890  
##  (Other)               :597023   NA's   :713     NA's   :1815    
##        y                z         
##  Min.   : 1.000   Min.   : 0.040  
##  1st Qu.: 4.970   1st Qu.: 3.120  
##  Median : 6.050   Median : 3.860  
##  Mean   : 6.199   Mean   : 4.033  
##  3rd Qu.: 7.230   3rd Qu.: 4.610  
##  Max.   :13.890   Max.   :13.180  
##  NA's   :1852     NA's   :2544
ajay2=c(23,45,78,NA,NA,89,NA)
is.na(ajay2)
## [1] FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE
table(is.na(BigDiamonds2$price))
## 
##  FALSE   TRUE 
## 597311    713
mean(BigDiamonds2$price,na.rm = T)
## [1] 8753.018
diamondsforever=na.omit(BigDiamonds2)
summary(diamondsforever)
##        X              carat           cut             color      
##  Min.   :   494   Min.   :0.200   Good  : 59149   G      :95363  
##  1st Qu.:149638   1st Qu.:0.500   Ideal :367026   E      :92859  
##  Median :299312   Median :0.900   V.Good:167609   F      :92772  
##  Mean   :299221   Mean   :1.073                   H      :85951  
##  3rd Qu.:448775   3rd Qu.:1.500                   D      :73201  
##  Max.   :598024   Max.   :9.250                   I      :69879  
##                                                   (Other):83759  
##     clarity           table           depth               cert       
##  SI1    :115898   Min.   : 0.00   Min.   : 0.00   GIA       :460036  
##  VS2    :110402   1st Qu.:56.00   1st Qu.:61.00   IGI       : 43339  
##  SI2    :103671   Median :58.00   Median :62.00   EGL       : 33722  
##  VS1    : 97113   Mean   :57.66   Mean   :61.09   EGL USA   : 16019  
##  VVS2   : 65002   3rd Qu.:59.00   3rd Qu.:62.70   EGL Intl. : 11439  
##  VVS1   : 54284   Max.   :75.90   Max.   :81.30   EGL ISRAEL: 11285  
##  (Other): 47414                                   (Other)   : 17944  
##              measurements        price             x         
##  4.3 x 4.27 x 2.67 :    97   Min.   :  300   Min.   : 0.150  
##  4.31 x 4.29 x 2.68:    87   1st Qu.: 1218   1st Qu.: 4.740  
##  4.29 x 4.26 x 2.67:    86   Median : 3503   Median : 5.780  
##  4.3 x 4.28 x 2.67 :    84   Mean   : 8756   Mean   : 5.992  
##  4.3 x 4.28 x 2.68 :    83   3rd Qu.:11186   3rd Qu.: 6.970  
##  4.29 x 4.26 x 2.66:    80   Max.   :99990   Max.   :13.890  
##  (Other)           :593267                                   
##        y                z         
##  Min.   : 1.000   Min.   : 0.040  
##  1st Qu.: 4.970   1st Qu.: 3.120  
##  Median : 6.050   Median : 3.860  
##  Mean   : 6.201   Mean   : 4.036  
##  3rd Qu.: 7.230   3rd Qu.: 4.610  
##  Max.   :13.890   Max.   :13.180  
## 
nrow(BigDiamonds2)-nrow(diamondsforever)
## [1] 4240
#iris

par(mfrow=c(2,4))
plot(iris$Sepal.Length)
plot(iris$Sepal.Length,type='l')
hist(iris$Sepal.Length)
boxplot(iris$Sepal.Length)
barplot(iris$Sepal.Length)
pie(table(iris$Species))
boxplot(iris$Sepal.Length~iris$Species)

money=c("50000","$50000","50,000","$50,000",50000)
money=gsub(",","",money)
money=gsub("\\$","",money)
money=as.numeric(money)
money
## [1] 50000 50000 50000 50000 50000
mean(money) 
## [1] 50000
#install.packages("lubridate")
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
dates=c("26jun98","1/09/2005","1January2016")
dates2=dmy(dates)
dates2
## [1] "1998-06-26" "2005-09-01" "2016-01-01"
ages=difftime(Sys.Date(),dates2)
ages
## Time differences in days
## [1] 6804 4180  406
dates3=c("7jun77")
dates4=dmy(dates3)
ages=difftime(Sys.Date(),dates4)
ages
## Time difference of 14493 days
names=c("John","rambo")
substr(names,1,2)
## [1] "Jo" "ra"
nchar(names)
## [1] 4 5
paste(ages)
## [1] "14493"
iris[1,]
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length2
## 1          5.1         3.5          1.4         0.2  setosa         163.2
iris[,1]
##   [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4
##  [18] 5.1 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5
##  [35] 4.9 5.0 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6 5.3 5.0 7.0
##  [52] 6.4 6.9 5.5 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1 5.6 6.7 5.6 5.8
##  [69] 6.2 5.6 5.9 6.1 6.3 6.1 6.4 6.6 6.8 6.7 6.0 5.7 5.5 5.5 5.8 6.0 5.4
##  [86] 6.0 6.7 6.3 5.6 5.5 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 5.1 5.7 6.3 5.8
## [103] 7.1 6.3 6.5 7.6 4.9 7.3 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7 7.7
## [120] 6.0 6.9 5.6 7.7 6.3 6.7 7.2 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7
## [137] 6.3 6.4 6.0 6.9 6.7 6.9 5.8 6.8 6.7 6.7 6.3 6.5 6.2 5.9
iris[3,]
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length2
## 3          4.7         3.2          1.3         0.2  setosa         150.4
iris2=subset(iris,iris$Sepal.Length>5 | Species=="setosa")
iris2
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1            5.1         3.5          1.4         0.2     setosa
## 2            4.9         3.0          1.4         0.2     setosa
## 3            4.7         3.2          1.3         0.2     setosa
## 4            4.6         3.1          1.5         0.2     setosa
## 5            5.0         3.6          1.4         0.2     setosa
## 6            5.4         3.9          1.7         0.4     setosa
## 7            4.6         3.4          1.4         0.3     setosa
## 8            5.0         3.4          1.5         0.2     setosa
## 9            4.4         2.9          1.4         0.2     setosa
## 10           4.9         3.1          1.5         0.1     setosa
## 11           5.4         3.7          1.5         0.2     setosa
## 12           4.8         3.4          1.6         0.2     setosa
## 13           4.8         3.0          1.4         0.1     setosa
## 14           4.3         3.0          1.1         0.1     setosa
## 15           5.8         4.0          1.2         0.2     setosa
## 16           5.7         4.4          1.5         0.4     setosa
## 17           5.4         3.9          1.3         0.4     setosa
## 18           5.1         3.5          1.4         0.3     setosa
## 19           5.7         3.8          1.7         0.3     setosa
## 20           5.1         3.8          1.5         0.3     setosa
## 21           5.4         3.4          1.7         0.2     setosa
## 22           5.1         3.7          1.5         0.4     setosa
## 23           4.6         3.6          1.0         0.2     setosa
## 24           5.1         3.3          1.7         0.5     setosa
## 25           4.8         3.4          1.9         0.2     setosa
## 26           5.0         3.0          1.6         0.2     setosa
## 27           5.0         3.4          1.6         0.4     setosa
## 28           5.2         3.5          1.5         0.2     setosa
## 29           5.2         3.4          1.4         0.2     setosa
## 30           4.7         3.2          1.6         0.2     setosa
## 31           4.8         3.1          1.6         0.2     setosa
## 32           5.4         3.4          1.5         0.4     setosa
## 33           5.2         4.1          1.5         0.1     setosa
## 34           5.5         4.2          1.4         0.2     setosa
## 35           4.9         3.1          1.5         0.2     setosa
## 36           5.0         3.2          1.2         0.2     setosa
## 37           5.5         3.5          1.3         0.2     setosa
## 38           4.9         3.6          1.4         0.1     setosa
## 39           4.4         3.0          1.3         0.2     setosa
## 40           5.1         3.4          1.5         0.2     setosa
## 41           5.0         3.5          1.3         0.3     setosa
## 42           4.5         2.3          1.3         0.3     setosa
## 43           4.4         3.2          1.3         0.2     setosa
## 44           5.0         3.5          1.6         0.6     setosa
## 45           5.1         3.8          1.9         0.4     setosa
## 46           4.8         3.0          1.4         0.3     setosa
## 47           5.1         3.8          1.6         0.2     setosa
## 48           4.6         3.2          1.4         0.2     setosa
## 49           5.3         3.7          1.5         0.2     setosa
## 50           5.0         3.3          1.4         0.2     setosa
## 51           7.0         3.2          4.7         1.4 versicolor
## 52           6.4         3.2          4.5         1.5 versicolor
## 53           6.9         3.1          4.9         1.5 versicolor
## 54           5.5         2.3          4.0         1.3 versicolor
## 55           6.5         2.8          4.6         1.5 versicolor
## 56           5.7         2.8          4.5         1.3 versicolor
## 57           6.3         3.3          4.7         1.6 versicolor
## 59           6.6         2.9          4.6         1.3 versicolor
## 60           5.2         2.7          3.9         1.4 versicolor
## 62           5.9         3.0          4.2         1.5 versicolor
## 63           6.0         2.2          4.0         1.0 versicolor
## 64           6.1         2.9          4.7         1.4 versicolor
## 65           5.6         2.9          3.6         1.3 versicolor
## 66           6.7         3.1          4.4         1.4 versicolor
## 67           5.6         3.0          4.5         1.5 versicolor
## 68           5.8         2.7          4.1         1.0 versicolor
## 69           6.2         2.2          4.5         1.5 versicolor
## 70           5.6         2.5          3.9         1.1 versicolor
## 71           5.9         3.2          4.8         1.8 versicolor
## 72           6.1         2.8          4.0         1.3 versicolor
## 73           6.3         2.5          4.9         1.5 versicolor
## 74           6.1         2.8          4.7         1.2 versicolor
## 75           6.4         2.9          4.3         1.3 versicolor
## 76           6.6         3.0          4.4         1.4 versicolor
## 77           6.8         2.8          4.8         1.4 versicolor
## 78           6.7         3.0          5.0         1.7 versicolor
## 79           6.0         2.9          4.5         1.5 versicolor
## 80           5.7         2.6          3.5         1.0 versicolor
## 81           5.5         2.4          3.8         1.1 versicolor
## 82           5.5         2.4          3.7         1.0 versicolor
## 83           5.8         2.7          3.9         1.2 versicolor
## 84           6.0         2.7          5.1         1.6 versicolor
## 85           5.4         3.0          4.5         1.5 versicolor
## 86           6.0         3.4          4.5         1.6 versicolor
## 87           6.7         3.1          4.7         1.5 versicolor
## 88           6.3         2.3          4.4         1.3 versicolor
## 89           5.6         3.0          4.1         1.3 versicolor
## 90           5.5         2.5          4.0         1.3 versicolor
## 91           5.5         2.6          4.4         1.2 versicolor
## 92           6.1         3.0          4.6         1.4 versicolor
## 93           5.8         2.6          4.0         1.2 versicolor
## 95           5.6         2.7          4.2         1.3 versicolor
## 96           5.7         3.0          4.2         1.2 versicolor
## 97           5.7         2.9          4.2         1.3 versicolor
## 98           6.2         2.9          4.3         1.3 versicolor
## 99           5.1         2.5          3.0         1.1 versicolor
## 100          5.7         2.8          4.1         1.3 versicolor
## 101          6.3         3.3          6.0         2.5  virginica
## 102          5.8         2.7          5.1         1.9  virginica
## 103          7.1         3.0          5.9         2.1  virginica
## 104          6.3         2.9          5.6         1.8  virginica
## 105          6.5         3.0          5.8         2.2  virginica
## 106          7.6         3.0          6.6         2.1  virginica
## 108          7.3         2.9          6.3         1.8  virginica
## 109          6.7         2.5          5.8         1.8  virginica
## 110          7.2         3.6          6.1         2.5  virginica
## 111          6.5         3.2          5.1         2.0  virginica
## 112          6.4         2.7          5.3         1.9  virginica
## 113          6.8         3.0          5.5         2.1  virginica
## 114          5.7         2.5          5.0         2.0  virginica
## 115          5.8         2.8          5.1         2.4  virginica
## 116          6.4         3.2          5.3         2.3  virginica
## 117          6.5         3.0          5.5         1.8  virginica
## 118          7.7         3.8          6.7         2.2  virginica
## 119          7.7         2.6          6.9         2.3  virginica
## 120          6.0         2.2          5.0         1.5  virginica
## 121          6.9         3.2          5.7         2.3  virginica
## 122          5.6         2.8          4.9         2.0  virginica
## 123          7.7         2.8          6.7         2.0  virginica
## 124          6.3         2.7          4.9         1.8  virginica
## 125          6.7         3.3          5.7         2.1  virginica
## 126          7.2         3.2          6.0         1.8  virginica
## 127          6.2         2.8          4.8         1.8  virginica
## 128          6.1         3.0          4.9         1.8  virginica
## 129          6.4         2.8          5.6         2.1  virginica
## 130          7.2         3.0          5.8         1.6  virginica
## 131          7.4         2.8          6.1         1.9  virginica
## 132          7.9         3.8          6.4         2.0  virginica
## 133          6.4         2.8          5.6         2.2  virginica
## 134          6.3         2.8          5.1         1.5  virginica
## 135          6.1         2.6          5.6         1.4  virginica
## 136          7.7         3.0          6.1         2.3  virginica
## 137          6.3         3.4          5.6         2.4  virginica
## 138          6.4         3.1          5.5         1.8  virginica
## 139          6.0         3.0          4.8         1.8  virginica
## 140          6.9         3.1          5.4         2.1  virginica
## 141          6.7         3.1          5.6         2.4  virginica
## 142          6.9         3.1          5.1         2.3  virginica
## 143          5.8         2.7          5.1         1.9  virginica
## 144          6.8         3.2          5.9         2.3  virginica
## 145          6.7         3.3          5.7         2.5  virginica
## 146          6.7         3.0          5.2         2.3  virginica
## 147          6.3         2.5          5.0         1.9  virginica
## 148          6.5         3.0          5.2         2.0  virginica
## 149          6.2         3.4          5.4         2.3  virginica
## 150          5.9         3.0          5.1         1.8  virginica
##     Sepal.Length2
## 1           163.2
## 2           156.8
## 3           150.4
## 4           147.2
## 5           160.0
## 6           172.8
## 7           147.2
## 8           160.0
## 9           140.8
## 10          156.8
## 11          172.8
## 12          153.6
## 13          153.6
## 14          137.6
## 15          185.6
## 16          182.4
## 17          172.8
## 18          163.2
## 19          182.4
## 20          163.2
## 21          172.8
## 22          163.2
## 23          147.2
## 24          163.2
## 25          153.6
## 26          160.0
## 27          160.0
## 28          166.4
## 29          166.4
## 30          150.4
## 31          153.6
## 32          172.8
## 33          166.4
## 34          176.0
## 35          156.8
## 36          160.0
## 37          176.0
## 38          156.8
## 39          140.8
## 40          163.2
## 41          160.0
## 42          144.0
## 43          140.8
## 44          160.0
## 45          163.2
## 46          153.6
## 47          163.2
## 48          147.2
## 49          169.6
## 50          160.0
## 51          224.0
## 52          204.8
## 53          220.8
## 54          176.0
## 55          208.0
## 56          182.4
## 57          201.6
## 59          211.2
## 60          166.4
## 62          188.8
## 63          192.0
## 64          195.2
## 65          179.2
## 66          214.4
## 67          179.2
## 68          185.6
## 69          198.4
## 70          179.2
## 71          188.8
## 72          195.2
## 73          201.6
## 74          195.2
## 75          204.8
## 76          211.2
## 77          217.6
## 78          214.4
## 79          192.0
## 80          182.4
## 81          176.0
## 82          176.0
## 83          185.6
## 84          192.0
## 85          172.8
## 86          192.0
## 87          214.4
## 88          201.6
## 89          179.2
## 90          176.0
## 91          176.0
## 92          195.2
## 93          185.6
## 95          179.2
## 96          182.4
## 97          182.4
## 98          198.4
## 99          163.2
## 100         182.4
## 101         201.6
## 102         185.6
## 103         227.2
## 104         201.6
## 105         208.0
## 106         243.2
## 108         233.6
## 109         214.4
## 110         230.4
## 111         208.0
## 112         204.8
## 113         217.6
## 114         182.4
## 115         185.6
## 116         204.8
## 117         208.0
## 118         246.4
## 119         246.4
## 120         192.0
## 121         220.8
## 122         179.2
## 123         246.4
## 124         201.6
## 125         214.4
## 126         230.4
## 127         198.4
## 128         195.2
## 129         204.8
## 130         230.4
## 131         236.8
## 132         252.8
## 133         204.8
## 134         201.6
## 135         195.2
## 136         246.4
## 137         201.6
## 138         204.8
## 139         192.0
## 140         220.8
## 141         214.4
## 142         220.8
## 143         185.6
## 144         217.6
## 145         214.4
## 146         214.4
## 147         201.6
## 148         208.0
## 149         198.4
## 150         188.8