Sunteți pe pagina 1din 12

R version 3.5.

1 (2018-07-02) -- "Feather Spray"


Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.


You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.


Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or


'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 33+66
[1] 99
> 33+666
[1] 699
> 33+666
[1] 699
> 5*20
[1] 100
> a=5
> b=20
> c=a*b
> c
[1] 100
> a=c(28, 5.8, 59)
> a
[1] 28.0 5.8 59.0
> a[3]
[1] 59
> b<-3
> b
[1] 3
> 4->b
> b
[1] 4
> b<-c(1:90,215:2220)
> b<-c(1:90,215,220)
> b
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20
[21] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40
[41] 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
60
[61] 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
80
[81] 81 82 83 84 85 86 87 88 89 90 215 220
> b[22]
[1] 22
> class(b)
[1] "numeric"
> c=c("Shillong", "Meghalaya", "India")
> class(c)
[1] "character"
> c=c("Shillong", "Meghalaya", "India")
> class(c)
[1] "character"
> c
[1] "Shillong" "Meghalaya" "India"
> c[4]
[1] NA
> c[3]
[1] "India"
> d=c(b,c)
> class(d)
[1] "character"
> d
[1] "1" "2" "3" "4" "5" "6"
[7] "7" "8" "9" "10" "11" "12"
[13] "13" "14" "15" "16" "17" "18"
[19] "19" "20" "21" "22" "23" "24"
[25] "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36"
[37] "37" "38" "39" "40" "41" "42"
[43] "43" "44" "45" "46" "47" "48"
[49] "49" "50" "51" "52" "53" "54"
[55] "55" "56" "57" "58" "59" "60"
[61] "61" "62" "63" "64" "65" "66"
[67] "67" "68" "69" "70" "71" "72"
[73] "73" "74" "75" "76" "77" "78"
[79] "79" "80" "81" "82" "83" "84"
[85] "85" "86" "87" "88" "89" "90"
[91] "215" "220" "Shillong" "Meghalaya" "India"
> a
[1] 28.0 5.8 59.0
> e=list(a,c)
> class(e)
[1] "list"
> e
[[1]]
[1] 28.0 5.8 59.0

[[2]]
[1] "Shillong" "Meghalaya" "India"

> e[2][3]
[[1]]
NULL

> e[2,3]
Error in e[2, 3] : incorrect number of dimensions
> e[[2]][3]
[1] "India"
> e[[2]]
[1] "Shillong" "Meghalaya" "India"
> e[1]
[[1]]
[1] 28.0 5.8 59.0

> e[2]
[[1]]
[1] "Shillong" "Meghalaya" "India"
> class(e[2])
[1] "list"
> class(e[[2]])
[1] "character"
> m=matrix(c(1:9),nrow=3)
> class(m)
[1] "matrix"
> m
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> m[1,1]
[1] 1
> m[2,1]
[1] 2
> m=matrix(c(1:9),nrow=3, byrow=T)
> m
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> n=matrix(c(11:19),nrow=3, byrow=T)
> n
[,1] [,2] [,3]
[1,] 11 12 13
[2,] 14 15 16
[3,] 17 18 19
> o=m*n
> o
[,1] [,2] [,3]
[1,] 11 24 39
[2,] 56 75 96
[3,] 119 144 171
> p=m%*%n
> p
[,1] [,2] [,3]
[1,] 90 96 102
[2,] 216 231 246
[3,] 342 366 390
> savehistory("C:/Users/deepak/Desktop/Term 5/Business Intelligence and
Analytics/Session VII.Rhistory")
> setwd("C:/Users/deepak/Desktop/Term 5/Business Intelligence and Analytics")
> hsb=read.csv("hsb2.csv")
> class(hsb)
[1] "data.frame"
> hsb
id female race ses schtyp prog read write math science socst
1 70 0 4 1 1 1 57 52 41 47 57
2 121 1 4 2 1 3 68 59 53 63 61
3 86 0 4 3 1 1 44 33 54 58 31
4 141 0 4 3 1 3 63 44 47 53 56
5 172 0 4 2 1 2 47 52 57 53 61
6 113 0 4 2 1 2 44 52 51 63 61
7 50 0 3 2 1 1 50 59 42 53 61
8 11 0 1 2 1 2 34 46 45 39 36
9 84 0 4 2 1 1 63 57 54 58 51
10 48 0 3 2 1 2 57 55 52 50 51
11 75 0 4 2 1 3 60 46 51 53 61
12 60 0 4 2 1 2 57 65 51 63 61
13 95 0 4 3 1 2 73 60 71 61 71
14 104 0 4 3 1 2 54 63 57 55 46
15 38 0 3 1 1 2 45 57 50 31 56
16 115 0 4 1 1 1 42 49 43 50 56
17 76 0 4 3 1 2 47 52 51 50 56
18 195 0 4 2 2 1 57 57 60 58 56
19 114 0 4 3 1 2 68 65 62 55 61
20 85 0 4 2 1 1 55 39 57 53 46
21 167 0 4 2 1 1 63 49 35 66 41
22 143 0 4 2 1 3 63 63 75 72 66
23 41 0 3 2 1 2 50 40 45 55 56
24 20 0 1 3 1 2 60 52 57 61 61
25 12 0 1 2 1 3 37 44 45 39 46
26 53 0 3 2 1 3 34 37 46 39 31
27 154 0 4 3 1 2 65 65 66 61 66
28 178 0 4 2 2 3 47 57 57 58 46
29 196 0 4 3 2 2 44 38 49 39 46
30 29 0 2 1 1 1 52 44 49 55 41
31 126 0 4 2 1 1 42 31 57 47 51
32 103 0 4 3 1 2 76 52 64 64 61
33 192 0 4 3 2 2 65 67 63 66 71
34 150 0 4 2 1 3 42 41 57 72 31
35 199 0 4 3 2 2 52 59 50 61 61
36 144 0 4 3 1 1 60 65 58 61 66
37 200 0 4 2 2 2 68 54 75 66 66
38 80 0 4 3 1 2 65 62 68 66 66
39 16 0 1 1 1 3 47 31 44 36 36
40 153 0 4 2 1 3 39 31 40 39 51
41 176 0 4 2 2 2 47 47 41 42 51
42 177 0 4 2 2 2 55 59 62 58 51
43 168 0 4 2 1 2 52 54 57 55 51
44 40 0 3 1 1 1 42 41 43 50 41
45 62 0 4 3 1 1 65 65 48 63 66
46 169 0 4 1 1 1 55 59 63 69 46
47 49 0 3 3 1 3 50 40 39 49 47
48 136 0 4 2 1 2 65 59 70 63 51
49 189 0 4 2 2 2 47 59 63 53 46
50 7 0 1 2 1 2 57 54 59 47 51
51 27 0 2 2 1 2 53 61 61 57 56
52 128 0 4 3 1 2 39 33 38 47 41
53 21 0 1 2 1 1 44 44 61 50 46
54 183 0 4 2 2 2 63 59 49 55 71
55 132 0 4 2 1 2 73 62 73 69 66
56 15 0 1 3 1 3 39 39 44 26 42
57 67 0 4 1 1 3 37 37 42 33 32
58 22 0 1 2 1 3 42 39 39 56 46
59 185 0 4 2 2 2 63 57 55 58 41
60 9 0 1 2 1 3 48 49 52 44 51
61 181 0 4 2 2 2 50 46 45 58 61
62 170 0 4 3 1 2 47 62 61 69 66
63 134 0 4 1 1 1 44 44 39 34 46
64 108 0 4 2 1 1 34 33 41 36 36
65 197 0 4 3 2 2 50 42 50 36 61
66 140 0 4 2 1 3 44 41 40 50 26
67 171 0 4 2 1 2 60 54 60 55 66
68 107 0 4 1 1 3 47 39 47 42 26
69 81 0 4 1 1 2 63 43 59 65 44
70 18 0 1 2 1 3 50 33 49 44 36
71 155 0 4 2 1 1 44 44 46 39 51
72 97 0 4 3 1 2 60 54 58 58 61
73 68 0 4 2 1 2 73 67 71 63 66
74 157 0 4 2 1 1 68 59 58 74 66
75 56 0 4 2 1 3 55 45 46 58 51
76 5 0 1 1 1 2 47 40 43 45 31
77 159 0 4 3 1 2 55 61 54 49 61
78 123 0 4 3 1 1 68 59 56 63 66
79 164 0 4 2 1 3 31 36 46 39 46
80 14 0 1 3 1 2 47 41 54 42 56
81 127 0 4 3 1 2 63 59 57 55 56
82 165 0 4 1 1 3 36 49 54 61 36
83 174 0 4 2 2 2 68 59 71 66 56
84 3 0 1 1 1 2 63 65 48 63 56
85 58 0 4 2 1 3 55 41 40 44 41
86 146 0 4 3 1 2 55 62 64 63 66
87 102 0 4 3 1 2 52 41 51 53 56
88 117 0 4 3 1 3 34 49 39 42 56
89 133 0 4 2 1 3 50 31 40 34 31
90 94 0 4 3 1 2 55 49 61 61 56
[ reached getOption("max.print") -- omitted 110 rows ]
> head(hsb)
id female race ses schtyp prog read write math science socst
1 70 0 4 1 1 1 57 52 41 47 57
2 121 1 4 2 1 3 68 59 53 63 61
3 86 0 4 3 1 1 44 33 54 58 31
4 141 0 4 3 1 3 63 44 47 53 56
5 172 0 4 2 1 2 47 52 57 53 61
6 113 0 4 2 1 2 44 52 51 63 61
> tail(hsb)
id female race ses schtyp prog read write math science socst
195 179 1 4 2 2 2 47 65 60 50 56
196 31 1 2 2 2 1 55 59 52 42 56
197 145 1 4 2 1 3 42 46 38 36 46
198 187 1 4 2 2 1 57 41 57 55 52
199 118 1 4 2 1 1 55 62 58 58 61
200 137 1 4 3 1 2 63 65 65 53 61
> summary(hsb)
id female race ses schtyp
Min. : 1.00 Min. :0.000 Min. :1.00 Min. :1.000 Min. :1.00
1st Qu.: 50.75 1st Qu.:0.000 1st Qu.:3.00 1st Qu.:2.000 1st Qu.:1.00
Median :100.50 Median :1.000 Median :4.00 Median :2.000 Median :1.00
Mean :100.50 Mean :0.545 Mean :3.43 Mean :2.055 Mean :1.16
3rd Qu.:150.25 3rd Qu.:1.000 3rd Qu.:4.00 3rd Qu.:3.000 3rd Qu.:1.00
Max. :200.00 Max. :1.000 Max. :4.00 Max. :3.000 Max. :2.00
prog read write math science
Min. :1.000 Min. :28.00 Min. :31.00 Min. :33.00 Min. :26.00
1st Qu.:2.000 1st Qu.:44.00 1st Qu.:45.75 1st Qu.:45.00 1st Qu.:44.00
Median :2.000 Median :50.00 Median :54.00 Median :52.00 Median :53.00
Mean :2.025 Mean :52.23 Mean :52.77 Mean :52.65 Mean :51.85
3rd Qu.:2.250 3rd Qu.:60.00 3rd Qu.:60.00 3rd Qu.:59.00 3rd Qu.:58.00
Max. :3.000 Max. :76.00 Max. :67.00 Max. :75.00 Max. :74.00
socst
Min. :26.00
1st Qu.:46.00
Median :52.00
Mean :52.41
3rd Qu.:61.00
Max. :71.00
> describe(hsb)
Error in describe(hsb) : could not find function "describe"
> ?summary
> ?class
> ?describe
No documentation for ‘describe’ in specified packages and libraries:
you could try ‘??describe’
> install.packages("psych")
Installing package into ‘C:/Users/deepak/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependency ‘mnormt’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/mnormt_1.5-5.zip'


Content type 'application/zip' length 373388 bytes (364 KB)
downloaded 364 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/psych_1.8.4.zip'


Content type 'application/zip' length 5741016 bytes (5.5 MB)
downloaded 5.5 MB

package ‘mnormt’ successfully unpacked and MD5 sums checked


package ‘psych’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\deepak\AppData\Local\Temp\RtmpoBdZOI\downloaded_packages
> ?describe
No documentation for ‘describe’ in specified packages and libraries:
you could try ‘??describe’
> library(psych)
> ?describe
> describe(hsb)
vars n mean sd median trimmed mad min max range skew kurtosis
id 1 200 100.50 57.88 100.5 100.50 74.13 1 200 199 0.00 -1.22
female 2 200 0.55 0.50 1.0 0.56 0.00 0 1 1 -0.18 -1.98
race 3 200 3.43 1.04 4.0 3.66 0.00 1 4 3 -1.56 0.85
ses 4 200 2.06 0.72 2.0 2.07 1.48 1 3 2 -0.08 -1.10
schtyp 5 200 1.16 0.37 1.0 1.07 0.00 1 2 1 1.84 1.40
prog 6 200 2.02 0.69 2.0 2.03 0.00 1 3 2 -0.03 -0.91
read 7 200 52.23 10.25 50.0 52.03 10.38 28 76 48 0.19 -0.66
write 8 200 52.77 9.48 54.0 53.36 11.86 31 67 36 -0.47 -0.78
math 9 200 52.65 9.37 52.0 52.23 10.38 33 75 42 0.28 -0.69
science 10 200 51.85 9.90 53.0 52.02 11.86 26 74 48 -0.19 -0.60
socst 11 200 52.41 10.74 52.0 52.99 13.34 26 71 45 -0.38 -0.57
se
id 4.09
female 0.04
race 0.07
ses 0.05
schtyp 0.03
prog 0.05
read 0.72
write 0.67
math 0.66
science 0.70
socst 0.76
> describe(hsb)
vars n mean sd median trimmed mad min max range skew kurtosis
se
id 1 200 100.50 57.88 100.5 100.50 74.13 1 200 199 0.00 -1.22
4.09
female 2 200 0.55 0.50 1.0 0.56 0.00 0 1 1 -0.18 -1.98
0.04
race 3 200 3.43 1.04 4.0 3.66 0.00 1 4 3 -1.56 0.85
0.07
ses 4 200 2.06 0.72 2.0 2.07 1.48 1 3 2 -0.08 -1.10
0.05
schtyp 5 200 1.16 0.37 1.0 1.07 0.00 1 2 1 1.84 1.40
0.03
prog 6 200 2.02 0.69 2.0 2.03 0.00 1 3 2 -0.03 -0.91
0.05
read 7 200 52.23 10.25 50.0 52.03 10.38 28 76 48 0.19 -0.66
0.72
write 8 200 52.77 9.48 54.0 53.36 11.86 31 67 36 -0.47 -0.78
0.67
math 9 200 52.65 9.37 52.0 52.23 10.38 33 75 42 0.28 -0.69
0.66
science 10 200 51.85 9.90 53.0 52.02 11.86 26 74 48 -0.19 -0.60
0.70
socst 11 200 52.41 10.74 52.0 52.99 13.34 26 71 45 -0.38 -0.57
0.76
>
>
>
> names(hsb)
[1] "id" "female" "race" "ses" "schtyp" "prog" "read" "write"

[9] "math" "science" "socst"


>
>
>
> hsb$write
[1] 52 59 33 44 52 52 59 46 57 55 46 65 60 63 57 49 52 57 65 39 49 63 40 52 44 37
65 57
[29] 38 44 31 52 67 41 59 65 54 62 31 31 47 59 54 41 65 59 40 59 59 54 61 33 44 59
62 39
[57] 37 39 57 49 46 62 44 33 42 41 54 39 43 33 44 54 67 59 45 40 61 59 36 41 59 49
59 65
[85] 41 62 41 49 31 49 62 49 62 44 44 62 65 65 44 63 60 59 46 52 59 54 62 35 54 65
52 50
[113] 59 65 61 44 54 67 57 47 54 52 52 46 62 57 41 53 49 35 59 65 62 54 59 63 59 52
41 49
[141] 46 54 42 57 59 52 62 52 41 55 37 54 57 54 62 59 55 57 39 67 62 50 61 62 59 44
59 54
[169] 62 60 57 46 36 59 49 60 67 54 52 65 62 49 67 65 67 65 54 44 62 46 54 57 52 59
65 59
[197] 46 41 62 65
>
>
>
> hsb[2,8]
[1] 59
>
>
>
> hsb[2,]
id female race ses schtyp prog read write math science socst
2 121 1 4 2 1 3 68 59 53 63 61
>
>
>
> hsb[,8]
[1] 52 59 33 44 52 52 59 46 57 55 46 65 60 63 57 49 52 57 65 39 49 63 40 52 44 37
65 57
[29] 38 44 31 52 67 41 59 65 54 62 31 31 47 59 54 41 65 59 40 59 59 54 61 33 44 59
62 39
[57] 37 39 57 49 46 62 44 33 42 41 54 39 43 33 44 54 67 59 45 40 61 59 36 41 59 49
59 65
[85] 41 62 41 49 31 49 62 49 62 44 44 62 65 65 44 63 60 59 46 52 59 54 62 35 54 65
52 50
[113] 59 65 61 44 54 67 57 47 54 52 52 46 62 57 41 53 49 35 59 65 62 54 59 63 59 52
41 49
[141] 46 54 42 57 59 52 62 52 41 55 37 54 57 54 62 59 55 57 39 67 62 50 61 62 59 44
59 54
[169] 62 60 57 46 36 59 49 60 67 54 52 65 62 49 67 65 67 65 54 44 62 46 54 57 52 59
65 59
[197] 46 41 62 65
>
>
>
> hsb[8]
write
1 52
2 59
3 33
4 44
5 52
6 52
7 59
8 46
9 57
10 55
11 46
12 65
13 60
14 63
15 57
16 49
17 52
18 57
19 65
20 39
21 49
22 63
23 40
24 52
25 44
26 37
27 65
28 57
29 38
30 44
31 31
32 52
33 67
34 41
35 59
36 65
37 54
38 62
39 31
40 31
41 47
42 59
43 54
44 41
45 65
46 59
47 40
48 59
49 59
50 54
51 61
52 33
53 44
54 59
55 62
56 39
57 37
58 39
59 57
60 49
61 46
62 62
63 44
64 33
65 42
66 41
67 54
68 39
69 43
70 33
71 44
72 54
73 67
74 59
75 45
76 40
77 61
78 59
79 36
80 41
81 59
82 49
83 59
84 65
85 41
86 62
87 41
88 49
89 31
90 49
91 62
92 49
93 62
94 44
95 44
96 62
97 65
98 65
99 44
100 63
101 60
102 59
103 46
104 52
105 59
106 54
107 62
108 35
109 54
110 65
111 52
112 50
113 59
114 65
115 61
116 44
117 54
118 67
119 57
120 47
121 54
122 52
123 52
124 46
125 62
126 57
127 41
128 53
129 49
130 35
131 59
132 65
133 62
134 54
135 59
136 63
137 59
138 52
139 41
140 49
141 46
142 54
143 42
144 57
145 59
146 52
147 62
148 52
149 41
150 55
151 37
152 54
153 57
154 54
155 62
156 59
157 55
158 57
159 39
160 67
161 62
162 50
163 61
164 62
165 59
166 44
167 59
168 54
169 62
170 60
171 57
172 46
173 36
174 59
175 49
176 60
177 67
178 54
179 52
180 65
181 62
182 49
183 67
184 65
185 67
186 65
187 54
188 44
189 62
190 46
191 54
192 57
193 52
194 59
195 65
196 59
197 46
198 41
199 62
200 65
>
>
>
> head(hsb[,8])
[1] 52 59 33 44 52 52
>
>
>
> hsb[2,c(7,8)]
read write
2 68 59
>
>
>
> hsb[2,c(7,11)]
read socst
2 68 61
>
>
>
> hsb[2,c(7:11)]
read write math science socst
2 68 59 53 63 61
>
>
>
> savehistory("C:/Users/deepak/Desktop/Term 5/Business Intelligence and
Analytics/Session VII.Rhistory")

S-ar putea să vă placă și