7/26/2019 akarpersamaankuadrat(latihan r)
1/39
> akarpersamaankuadrat akarpersamaankuadrat akarpersamaankuadrat(1,-&,')
x1 x2
1, * 2
ersion *12 (2.1-1.-*1) -- /0umpkin e%met/
op3ri4$t () 2.1 5$e 6oundation for 7tatistica% omputin4
0%atform8 x9':'-;'-min4;*2"x' ('-bit)
is free soft;are and comes ;it$ 7?@5A?B C DC5B
Bou are ;e%come to redistribute it under certain conditions
53pe E%icense()E or E%icence()E for distribution detai%s
is a co%%aboratie proFect ;it$ man3 contributors
53pe Econtributors()E for more information and
Ecitation()E on $o; to cite or packa4es in pub%ications
53pe Edemo()E for some demos, E$e%p()E for on-%ine $e%p, or
E$e%pstart()E for an 5G? bro;ser interface to $e%p
53pe Eq()E to quit
7/26/2019 akarpersamaankuadrat(latihan r)
2/39
0reious%3 saed ;orkspace restored
> akarpersamaankuadrat akarpersamaankuadrat akarpersamaankuadrat(1,-&,')
x1 x2
1, * 2
> da> akarpersamaankuadrat akarpersamaankuadrat > akarpersamaankuadratE in />/
> + x1=(-b+sqrt(b^2-!a!c))"2!a
Arror8 obFect EbE not found
> + x2=(-b-sqrt(b^2-!a!c))"2!a
Arror8 obFect EbE not found
> + $asi%=cbind(x1,x2)
Arror in cbind(x1, x2) 8 obFect Ex1E not found
> + print($asi%)#
Arror8 unexpected E#E in /+ print($asi%)#/
7/26/2019 akarpersamaankuadrat(latihan r)
3/39
> > akarpersamaankuadrat(1,-&,')
Arror8 unexpected E>E in />/
> x1 x2
Arror8 unexpected s3mbo% in / x1 x2/
> 1, * 2
> data arian arian(data)
1 22&*999e-*1
> inersperka%ianmatriks
7/26/2019 akarpersamaankuadrat(latihan r)
4/39
+ perka%ian=x J!J 3
Arror8 unexpected E!E in8
/inersperka%ianmatriks inerperka%ianmatriks b=c(2,*,)
> matrik1=matrix(a,1,*)
> matrik2=matrix(b,*,1)
> perka%ian=matrik1 J!J matrik2
7/26/2019 akarpersamaankuadrat(latihan r)
5/39
Arror8 unexpected E!E in /perka%ian=matrik1 J!/
> perka%ian=matrix(matrik1 J!J matrik2)
Arror8 unexpected E!E in /perka%ian=matrix(matrik1 J!/
> matrik1 J!J matrik2
Arror8 unexpected E!E in /matrik1 J!/
> perka%ianmatrik perka%ian= matrik1J ! Jmatrik2
Arror8 unexpected E!E in /perka%ian= matrik1J !/
> perka%ian=matrik1!matrik2
Arror in matrik1 ! matrik2 8 non-conformab%e arra3s
> matrik1
,1 ,2 ,*
1, 1 2 *
> matrik2
,1
1, 2
2, *
*,
> matrik1J ! Jmatrik2
Arror8 unexpected E!E in /matrik1J !/
> matrik1 J!J matrik2
Arror8 unexpected E!E in /matrik1 J!/
> matrik1 ! matrik2
Arror in matrik1 ! matrik2 8 non-conformab%e arra3s
> perka%ian=matrik1K!Kmatrik2
> perka%ian
,1
7/26/2019 akarpersamaankuadrat(latihan r)
6/39
1, 2.
> inersperka%ianmatrik x=c(1,2,,*,&,2,1,1)
> 3=c(1,*,*,1,2,1,1,2)
> inersperka%ianmatrik(x,3)
,1 ,2
1, .12I119 -.1&2I12
2, -.211H'H .*11H'&
> x
1 1 2 * & 2 1 1
> matrix(x,2,)
,1 ,2 ,* ,
1, 1 & 1
2, 2 * 2 1
> x=c(1,&,2,2,,1,*,1)
> 3=c(1,*,2,1,*,1,1,2)
> inersperka%ianmatrik(x,3)
,1 ,2
1, .1******* -.1.
2, -..I****** .12
> da> x=c(1,&,2,2,,1,*,1)
Arror in da > x = c(1, &, 2, 2, , 1, *, 1) 8 obFect EdaE not found
> > 3=c(1,*,2,1,*,1,1,2)
7/26/2019 akarpersamaankuadrat(latihan r)
7/39
Arror8 unexpected E>E in />/
> > inersperka%ianmatrik(x,3)
Arror8 unexpected E>E in />/
> ,1 ,2
Arror8 unexpected EE in / /
> 1, .1******* -.1.
Arror8 unexpected EE in //
> 2, -..I****** .12
Arror8 unexpected EE in //
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> datamatrix
,1 ,2 ,* , ,&
1, 1.2HI1*. &I12912 H..9'*&99 H..22. 292I2*
2, '*'9H9'' I'H'H9 &92''.11 &9.II22 1H991.91
*, .IH**21 '1'H'9 &''92*H. *91I.H1 1'2.1.
, *&I*99H& 2'2H.I& H92&&9'.. IH9.19 'H9**.2I
&, 9**2& .'*99 *'.1I'9*2 .I.1'* &****&1.
', 'H'&2 *I*2** 9.9..H&H &21H2H 2H'I.&
H, I&I'91' 91&H.11 91III. *.1I9 &IH*'''H
9, -21HHI22 ''&1 2IH2&IH.& 1.'*1&9 *&1IH2'
I, -2H2HH19& *&91191 9H.1.'&& *&H*2& *H'HH*'
1., &*I99&* 22&.&9. &1I9HI1' *199*1 9I..*I
11, &*12.9I' 1*IIH22 '12I*.9 II*9I1 &2I'.&
12, 19&&&1H 1I1H'HI *&122H1 H1...2H I.9*II*9
1*, 299&H& *H*2& &*&I2&& 'H9''H* &*HH2H
1, .*29&.1& 99'I&& 29&'''*&' H*2H1.I *2.9I'
1&, I'1HH1.2 '&H*I -..H1''1H .'2.2 .*.&9&2H
1', ..I.9I* I'19. *'*2'2.' '111'. 2'&*'1*
7/26/2019 akarpersamaankuadrat(latihan r)
8/39
1H, .12'H1 '1*&2*' *92H29' 2'*.9* 1*'2H'
19, **H1.1** *22299 *H*H9HH* 92II1 1*&*22'&
1I, &1&19H& 1.9I.'' *H9*..& 1.'1*I' .I1.&91H
2., H9**I&'1 1'2121* H.H*.122 2HH9HI 1*19I2I&
> rataratabaris tes
7/26/2019 akarpersamaankuadrat(latihan r)
9/39
> ratarata app%3(datamatrix,1,ratarata)
1 'I2I*2
1 '9.2&'
1 '&1IHI9
1 HI2I&I1
1 &&*1119
1 &&9H'I1
1 HH2'''2
1 *I'HH1
1 &9*1&
1 '.1'&&
1 *.2H.1'
1 *29121&
1 9*2'2I
1 2II'I
1 *92HHH9
1 H291H2
1 '.19&9
1 '*2*H
1 2H&2*1&
1 1&H&2
1 'I2I*2 '9.2&' '&1IHI9 HI2I&I1 &&*1119 &&9H'I1 HH2'''2*I'HH1.
7/26/2019 akarpersamaankuadrat(latihan r)
10/39
I &9*1& '.1'&& *.2H.1' *29121& 9*2'2I. 2II'I. *92HHH9
H291H2
1H '.19&9 '*2*H 2H&2*1& 1&H&2
> mean(1.2HI1*.,&I12912,H..9'*&99,H..22.,292I2*)1 1.2HI1
> b
7/26/2019 akarpersamaankuadrat(latihan r)
11/39
1, . .
2, . .
*, . .
, . .
&, . .
', . .
H, . .
9, . .
I, . .
1., . .
11, . .
12, . .
1*, . .
1, . .
1&, . .
1', . .
1H, . .
19, . .
1I, . .
2., . .
21, . .
22, . .
2*, . .
2, . .
2&, . .
2', . .
2H, . .
29, . .
7/26/2019 akarpersamaankuadrat(latihan r)
12/39
2I, . .
*., . .
*1, . .
*2, . .
**, . .
*, . .
*&, . .
*', . .
*H, . .
*9, . .
*I, . .
., . .
1, . .
2, . .
*, . .
, . .
&, . .
', . .
H, . .
9, . .
I, . .
&., . .
&1, . .
&2, . .
&*, . .
&, . .
&&, . .
&', . .
7/26/2019 akarpersamaankuadrat(latihan r)
13/39
&H, . .
&9, . .
&I, . .
'., . .
'1, . .
'2, . .
'*, . .
', . .
'&, . .
'', . .
'H, . .
'9, . .
'I, . .
H., . .
H1, . .
H2, . .
H*, . .
H, . .
H&, . .
H', . .
HH, . .
H9, . .
HI, . .
9., . .
91, . .
92, . .
9*, . .
9, . .
7/26/2019 akarpersamaankuadrat(latihan r)
14/39
9&, . .
9', . .
9H, . .
99, . .
9I, . .
I., . .
I1, . .
I2, . .
I*, . .
I, . .
I&, . .
I', . .
IH, . .
I9, . .
II, . .
1.., . .
> n m for (i in 18n){
+ datamatrix
7/26/2019 akarpersamaankuadrat(latihan r)
15/39
Arror in M datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(datamatrix1,){
Arror8 unexpected E{E in /for (i in seq(datamatrix1,){/
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(datamatrix1,)
+ {
Arror8 unexpected E{E in8
/for (i in seq(datamatrix1,)
{/
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(datamatrix1,)
+ rata=sum(i)"%en4t$(i)
Arror8 unexpected s3mbo% in8
/for (i in seq(datamatrix1,)
rata/
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(datamatrix1,)){
+ rata=sum(i)"%en4t$(i)
+ print(i)#
1 1
1 2
1 *
1
1 &
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(datamatrix1,)){
+ rata=sum(i)"%en4t$(i)
7/26/2019 akarpersamaankuadrat(latihan r)
16/39
+ print(rata)#
1 1
1 2
1 *
1
1 &
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> for (i in seq(a%on4(datamatrix1,))){
+ rata=sum(datamatrixi)"%en4t$(i)
+ print(rata)#
Arror in seq(a%on4(datamatrix1, )) 8 cou%d not Lnd function /a%on4/
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> n for (i in seq(a%on4(n)){
Arror8 unexpected E{E in /for (i in seq(a%on4(n)){/
> for (i in seq(a%on4(n))){
+ rata=sum(ni)"%en4t$(n)
+ print(rata)#
Arror in seq(a%on4(n)) 8 cou%d not Lnd function /a%on4/
> for (i in seq:a%on4=n){
Arror8 unexpected E=E in /for (i in seq:a%on4=/
> datamatrix=matrix(rnorm(1..,&,*),nco%=&)
> n ratabaris
7/26/2019 akarpersamaankuadrat(latihan r)
17/39
rata=sum(n)"%en4t$(n)
print(rata)#
> ratabaris(datamatrix)
1 &11'2
> ratabaris
7/26/2019 akarpersamaankuadrat(latihan r)
18/39
>
> Nectors 21
Arror8 unexpected numeric constant in /Nectors 21/
>
> ectorEs a%ues can be numbers, strin4s, %o4ica% a%ues, or an3 ot$er t3pe, as
%on4 as t$e3Ere a%% t$e same t3pe 5r3 creatin4 a ector of numbers, %ike t$is8
Arror8 unexpected s3mbo% in / ector/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > c(, H, I)
Arror8 unexpected E>E in />/
> 1 H I
Arror8 unexpected EE in //
> 5$e c function (c is s$ort for ombine) creates a ne; ector b3 combinin4 a
%ist of a%ues
Arror8 unexpected s3mbo% in /5$e c/
>
> Co; tr3 creatin4 a ector ;it$ strin4s8
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > c(EaE, EbE, EcE)
Arror8 unexpected E>E in />/
> 1 /a/ /b/ /c/
Arror8 unexpected EE in //
> Nectors cannot $o%d a%ues ;it$ diPerent modes (t3pes) 5r3 mixin4 modes and
see ;$at $appens8
7/26/2019 akarpersamaankuadrat(latihan r)
19/39
Arror8 unexpected s3mbo% in /Nectors cannot/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > c(1, 5@A, /t$ree/)
Arror8 unexpected E>E in />/
> 1 /1/ /5@A/ /t$ree/
Arror8 unexpected EE in //
> %% t$e a%ues ;ere conerted to a sin4%e mode (c$aracters) so t$at t$e ector
can $o%d t$em a%%
Arror8 unexpected s3mbo% in /%% t$e/
>
> 7equence Nectors 22
Arror8 unexpected s3mbo% in /7equence Nectors/
>
> Qf 3ou need a ector ;it$ a sequence of numbers 3ou can create it ;it$
start8end notation ?etEs make a ector ;it$ a%ues from & t$rou4$ I8
Arror8 unexpected s3mbo% in /Qf 3ou/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > &8I
Arror8 unexpected E>E in />/
> 1 & ' H 9 I
Arror8 unexpected EE in //
> more ersati%e ;a3 to make sequences is to ca%% t$e seq function ?etEs do
t$e same t$in4 ;it$ seq8
Arror8 unexpected s3mbo% in / more/
>
7/26/2019 akarpersamaankuadrat(latihan r)
20/39
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > seq(&, I)
Arror8 unexpected E>E in />/
> 1 & ' H 9 I
Arror8 unexpected EE in //
> seq a%so a%%o;s 3ou to use increments ot$er t$an 1 5r3 it ;it$ steps of .&8
Arror8 unexpected s3mbo% in /seq a%so/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > seq(&, I, .&)
Arror8 unexpected E>E in />/
> 1 &. && '. '& H. H& 9. 9& I.
Arror8 unexpected EE in //
> Co; tr3 makin4 a ector ;it$ inte4ers from I do;n to &8
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > I8&
Arror8 unexpected E>E in />/
> 1 I 9 H ' &
Arror8 unexpected EE in //
> Nector ccess 2*
Arror8 unexpected s3mbo% in /Nector ccess/
>
> DeEre 4oin4 to create a ector ;it$ some strin4s in it for 3ou, and store it int$e sentence ariab%e
7/26/2019 akarpersamaankuadrat(latihan r)
21/39
+
+ Bou can retriee an indiidua% a%ue ;it$in a ector b3 proidin4 its numeric
index in square brackets 5r3 4ettin4 t$e t$ird a%ue8
++ edoomp%ete
+ > sentence sentence > sentence*
Arror8 unexpected E>E in />/
> 1 /p%ank/
Arror8 unexpected EE in //
> Gan3 %an4ua4es start arra3 indices at ., but Es ector indices start at 1 Ret
t$e Lrst a%ue b3 t3pin48
Arror8 unexpected s3mbo% in /Gan3 %an4ua4es/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentence1
Arror8 unexpected E>E in />/
> 1 /;a%k/
Arror8 unexpected EE in //
> Bou can assi4n ne; a%ues ;it$in an existin4 ector 5r3 c$an4in4 t$e t$ird
;ord to /do4/8
Arror8 unexpected s3mbo% in /Bou can/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
7/26/2019 akarpersamaankuadrat(latihan r)
22/39
> > sentence* E in />/
> Qf 3ou add ne; a%ues onto t$e end, t$e ector ;i%% 4ro; to accommodate
t$em ?etEs add a fourt$ ;ord8Arror8 unexpected s3mbo% in /Qf 3ou/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentence E in />/
> Bou can use a ector ;it$in t$e square brackets to access mu%tip%e a%ues 5r3
4ettin4 t$e Lrst and t$ird ;ords8
Arror8 unexpected s3mbo% in /Bou can/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentencec(1, *)
Arror8 unexpected E>E in />/
> 1 /;a%k/ /do4/
Arror8 unexpected EE in //
> 5$is means 3ou can retriee ran4es of a%ues Ret t$e second t$rou4$ fourt$
;ords8
Arror8 unexpected s3mbo% in /5$is means/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentence28
Arror8 unexpected E>E in />/
> 1 /t$e/ /do4/ /to/
7/26/2019 akarpersamaankuadrat(latihan r)
23/39
Arror8 unexpected EE in //
> Bou can a%so set ran4es of a%uesS Fust proide t$e a%ues in a ector dd
;ords & t$rou4$ H8
Arror8 unexpected s3mbo% in /Bou can/>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentence&8H E in />/
> Co; tr3 accessin4 t$e sixt$ ;ord of t$e sentence ector8
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sentence'
Arror8 unexpected E>E in />/
> 1 /poop/
Arror8 unexpected EE in //
> Nector Cames 2
Arror8 unexpected s3mbo% in /Nector Cames/
>
> 6or t$is c$a%%en4e, ;eE%% make a *-item ector for 3ou, and store it in t$e ranks
ariab%e
Arror8 unexpected s3mbo% in /6or t$is/
>
> Bou can assi4n names to a ectorEs e%ements b3 passin4 a second ector L%%ed
;it$ names to t$e names assi4nment function, %ike t$is8
Arror8 unexpected s3mbo% in /Bou can/
>
7/26/2019 akarpersamaankuadrat(latihan r)
24/39
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > ranks E in />/
> > names(ranks) E in />/
> ssi4nin4 names for a ector can act as usefu% %abe%s for t$e data e%o;, 3ou
can see ;$at our ector %ooks %ike no;
Arror8 unexpected s3mbo% in /ssi4nin4 names/
>
> Bou can a%so use t$e names to access t$e ectorEs a%ues 5r3 4ettin4 t$e a%ue
for t$e /Lrst/ rank8
Arror8 unexpected s3mbo% in /Bou can/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > ranks
Arror8 unexpected E>E in />/
> Lrst second t$ird
Arror8 unexpected s3mbo% in / Lrst second/
> 1 2 *
Arror8 unexpected numeric constant in / 1 2/
> > ranks/Lrst/
Arror8 unexpected E>E in />/
> Lrst
Arror8 obFect ELrstE not found
> 1
1 1
7/26/2019 akarpersamaankuadrat(latihan r)
25/39
> Co; set t$e current a%ue for t$e /t$ird/ rank to a diPerent a%ue usin4 t$e
name rat$er t$an t$e position
Arror8 unexpected s3mbo% in /Co; set/
>> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > ranks/t$ird/ E in />/
> 0%ottin4 ne Nector 2&
Arror8 unexpected s3mbo% in /0%ottin4 ne/
>
> 5$e barp%ot function dra;s a bar c$art ;it$ a ectorEs a%ues DeE%% make a
ne; ector for 3ou, and store it in t$e esse%s7unk ariab%e
Arror8 unexpected s3mbo% in /5$e barp%ot/
>
> Co; tr3 passin4 t$e ector to t$e barp%ot function8
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > esse%s7unk E in />/
> > barp%ot(esse%s7unk)
Arror8 unexpected E>E in />/
> .
1 .
> 1
1 1
> 2
7/26/2019 akarpersamaankuadrat(latihan r)
26/39
1 2
> *
1 *
>
1
> &
1 &
> Qf 3ou assi4n names to t$e ectorEs a%ues, ;i%% use t$ose names as %abe%s on
t$e bar p%ot ?etEs use t$e names assi4nment function a4ain8
Arror8 unexpected s3mbo% in /Qf 3ou/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > names(esse%s7unk) E in />/
> Co;, if 3ou ca%% barp%ot ;it$ t$e ector a4ain, 3ouE%% see t$e %abe%s8
Arror8 unexpected E,E in /Co;,/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > barp%ot(esse%s7unk)
Arror8 unexpected E>E in />/
> An4%and
Arror8 obFect EAn4%andE not found
> 6rance
Arror8 obFect E6ranceE not found
> Cor;a3
Arror8 obFect ECor;a3E not found
> .
7/26/2019 akarpersamaankuadrat(latihan r)
27/39
1 .
> 1
1 1
> 2
1 2
> *
1 *
>
1
> &
1 &
> Co;, tr3 ca%%in4 barp%ot on a ector of inte4ers ran4in4 from 1 t$rou4$ 1..8
Arror8 unexpected E,E in /Co;,/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > barp%ot(181..)
Arror8 unexpected E>E in />/
> .
1 .
> 2.
1 2.
> .
1 .
> '.
1 '.
> 9.
1 9.
7/26/2019 akarpersamaankuadrat(latihan r)
28/39
> 1..
1 1..
> Nector Gat$ 2'
Arror8 unexpected s3mbo% in /Nector Gat$/
>
> Gost arit$metic operations ;ork Fust as ;e%% on ectors as t$e3 do on sin4%e
a%ues DeE%% make anot$er samp%e ector for 3ou to ;ork ;it$, and store it in t$e
a ariab%e
Arror8 unexpected s3mbo% in /Gost arit$metic/
>
> Qf 3ou add a sca%ar (a sin4%e a%ue) to a ector, t$e sca%ar ;i%% be added to eac$
a%ue in t$e ector, returnin4 a ne; ector ;it$ t$e resu%ts 5r3 addin4 1 to eac$
e%ement in our ector8
Arror8 unexpected s3mbo% in /Qf 3ou/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a E in />/
> > a + 1
Arror8 unexpected E>E in />/
> 1 2 *
Arror8 unexpected EE in //
> 5$e same is true of diision, mu%tip%ication, or an3 ot$er basic arit$metic 5r3
diidin4 our ector b3 28
Arror8 unexpected s3mbo% in /5$e same/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a " 2
7/26/2019 akarpersamaankuadrat(latihan r)
29/39
Arror8 unexpected E>E in />/
> 1 .& 1. 1&
Arror8 unexpected EE in //
> Co; tr3 mu%tip%3in4 our ector b3 28
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a!2
Arror8 unexpected E>E in />/
> 1 2 '
Arror8 unexpected EE in //
> Qf 3ou add t;o ectors, ;i%% take eac$ a%ue from eac$ ector and add t$em
DeE%% make a second ector for 3ou to experiment ;it$, and store it in t$e b
ariab%e
Arror8 unexpected s3mbo% in /Qf 3ou/
>
> 5r3 addin4 it to t$e a ector8
Arror8 unexpected s3mbo% in /5r3 addin4/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > b
7/26/2019 akarpersamaankuadrat(latihan r)
30/39
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a-b
Arror8 unexpected E>E in />/
> 1 -* -* -*
Arror8 unexpected EE in //
> Bou can a%so take t;o ectors and compare eac$ item 7ee ;$ic$ a%ues in t$e
a ector are equa% to t$ose in a second ector8
Arror8 unexpected s3mbo% in /Bou can/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a == c(1, II, *)
Arror8 unexpected E>E in />/
> 1 5@A 6?7A 5@A
Arror8 unexpected EE in //
> Cotice t$at didnEt test ;$et$er t$e ;$o%e ectors ;ere equa%S it c$ecked
eac$ a%ue in t$e a ector a4ainst t$e a%ue at t$e same index in our ne; ector
Arror8 unexpected s3mbo% in /Cotice t$at/
>
> $eck if eac$ a%ue in t$e a ector is %ess t$an t$e correspondin4 a%ue in
anot$er ector8
Arror8 unexpected EifE in /$eck if/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > a
7/26/2019 akarpersamaankuadrat(latihan r)
31/39
Arror8 unexpected E>E in />/
> 1 6?7A 5@A 6?7A
Arror8 unexpected EE in //
> 6unctions t$at norma%%3 ;ork ;it$ sca%ars can operate on eac$ e%ement of aector, too 5r3 4ettin4 t$e sine of eac$ a%ue in our ector8
Arror8 unexpected s3mbo% in /6unctions t$at/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sin(a)
Arror8 unexpected E>E in />/
> 1 .91H1. .I.I2IH .1112..
Arror8 unexpected EE in //
> Co; tr3 4ettin4 t$e square roots ;it$ sqrt8
Arror8 unexpected s3mbo% in /Co; tr3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sqrt(a)
Arror8 unexpected E>E in />/
> 1 1...... 1121 1H*2.&1
Arror8 unexpected EE in //
> 7catter 0%ots 2H
Arror8 unexpected s3mbo% in /7catter 0%ots/
>
> 5$e p%ot function takes t;o ectors, one for T a%ues and one for B a%ues, and
dra;s a 4rap$ of t$em
Arror8 unexpected s3mbo% in /5$e p%ot/
>
7/26/2019 akarpersamaankuadrat(latihan r)
32/39
> ?etEs dra; a 4rap$ s$o;in4 t$e re%ations$ip of numbers and t$eir sines
+
+ 6irst, ;eE%% need some samp%e data DeE%% create a ector for 3ou ;it$ some
fractiona% a%ues bet;een . and 2., and store it in t$e x ariab%eArror8 unexpected strin4 constant in8
/
6irst, ;eE/
>
> Co;, tr3 creatin4 a second ector ;it$ t$e sines of t$ose a%ues8
Arror8 unexpected E,E in /Co;,/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > x E in />/
> > 3 E in />/
> 5$en simp%3 ca%% p%ot ;it$ 3our t;o ectors8
Arror8 unexpected s3mbo% in /5$en simp%3/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > p%ot(x, 3)
Arror8 unexpected E>E in />/
> Rreat FobO Cotice on t$e 4rap$ t$at a%ues from t$e Lrst ar4ument (x) are used
for t$e $oriUonta% axis, and a%ues from t$e second (3) for t$e ertica%
Arror8 unexpected s3mbo% in /Rreat Fob/
>
> &
7/26/2019 akarpersamaankuadrat(latihan r)
33/39
1 &
> 1.
1 1.
> 1&
1 1&
> 2.
1 2.
> -1.
1 -1
> -.&
1 -.&
> ..
1 .
> .&
1 .&
> 1.
1 1
> x
1 1 & 2 2 1 * 1
> 3
1 1 * 2 1 * 1 1 2
> Bour turn DeE%% create a ector ;it$ some ne4atie and positie a%ues for 3ou,and store it in t$e a%ues ariab%e
Arror8 unexpected s3mbo% in /Bour turn/
>
> DeE%% a%so create a second ector ;it$ t$e abso%ute a%ues of t$e Lrst, and
store it in t$e abso%utes ariab%e
+
7/26/2019 akarpersamaankuadrat(latihan r)
34/39
+ 5r3 p%ottin4 t$e ectors, ;it$ a%ues on t$e $oriUonta% axis, and abso%utes on
t$e ertica% axis
+
+ edoomp%ete+ > a%ues abso%utes p%ot(a%ues, abso%utes)
+ -1.
+ -&
+ .
+ &
+ 1.
+ .
+ 2
+
+ '
+ 9
+ 1.
+ a%ues
+ abso%utes
+ C Na%ues 29
+
+ 7ometimes, ;$en ;orkin4 ;it$ samp%e data, a 4ien a%ue isnEt aai%ab%e ut
itEs not a 4ood idea to Fust t$ro; t$ose a%ues out $as a a%ue t$at exp%icit%3
indicates a samp%e ;as not aai%ab%e8 C Gan3 functions t$at ;ork ;it$ ectors
treat t$is a%ue specia%%3
Arror8 unexpected strin4 constant in8
/
7ometimes, ;$en ;orkin4 ;it$ samp%e data, a 4ien a%ue isnE/
>
7/26/2019 akarpersamaankuadrat(latihan r)
35/39
> DeE%% create a ector for 3ou ;it$ a missin4 samp%e, and store it in t$e a
ariab%e
+
+ 5r3 to 4et t$e sum of its a%ues, and see ;$at t$e resu%t is8+
+ edoomp%ete
+ > a sum(a)
+ 1 C
+ 5$e sum is considered /not aai%ab%e/ b3 defau%t because one of t$e ectorEs
a%ues ;as C 5$is is t$e responsib%e t$in4 to doS ;onEt Fust b%it$e%3 add up
t$e numbers ;it$out ;arnin4 3ou about t$e incomp%ete data De can exp%icit%3
te%% sum (and man3 ot$er functions) to remoe C a%ues before t$e3 do t$eir
ca%cu%ations, $o;eer
Arror8 unexpected strin4 constant in8
/1 C
5$e sum is considered /not aai%ab%e/ b3 defau%t because one of t$e ectorE/
>
> emember t$at command to brin4 up $e%p for a functionV rin4 up
documentation for t$e sum function8
Arror8 unexpected s3mbo% in /emember t$at/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > $e%p(sum)
Arror8 unexpected E>E in />/
> sum packa4e8base Wocumentation
Arror8 unexpected s3mbo% in /sum packa4e/
>
> 7um of Nector A%ements
Arror8 unexpected s3mbo% in /7um of/
7/26/2019 akarpersamaankuadrat(latihan r)
36/39
>
> Wescription8
+ EsumE returns t$e sum of a%% t$e a%ues present in its ar4uments
Arror8 unexpected s3mbo% in8
/Wescription8
EsumE returns/
>
> @sa4e8
+ sum(, narm = 6?7A)
Arror8 obFect E@sa4eE not found
>
Arror8 EE used in an incorrect context
> s 3ou see in t$e documentation, sum can take an optiona% named ar4ument,
narm QtEs set to 6?7A b3 defau%t, but if 3ou set it to 5@A, a%% C ar4uments ;i%%
be remoed from t$e ector before t$e ca%cu%ation is performed
Arror8 unexpected s3mbo% in /s 3ou/
>
> 5r3 ca%%in4 sum a4ain, ;it$ narm set to 5@A8
Arror8 unexpected s3mbo% in /5r3 ca%%in4/
>
> edoomp%ete
Arror8 obFect Eedoomp%eteE not found
> > sum(a, narm = 5@A)
Arror8 unexpected E>E in />/
> 1 2.
Arror8 unexpected EE in //
> $apter 2 omp%eted
Arror8 unexpected numeric constant in /$apter 2/
>
7/26/2019 akarpersamaankuadrat(latihan r)
37/39
> $apter 2 ad4e
Arror8 unexpected numeric constant in /$apter 2/
> 7$are 3our p%under8
Arror8 unexpected s3mbo% in /7$are 3our/
>
> BouEe traersed $apter 2X and discoered anot$er bad4eO Qf 3ouEd %ike to
add t$is to 3our ode 7c$oo% account, c%ick $ere to %o4 in oer on ode 7c$oo%, if
3ouEd %ike to add it to 3our account
Arror8 unexpected strin4 constant in /BouEe traersed $apter 2X and
discoered anot$er bad4eO Qf 3ouE/
>
> Qn t$is c$apter, ;eEe s$o;n 3ou a%% t$e basics of manipu%atin4 ectors -
creatin4 and accessin4 t$em, doin4 mat$ ;it$ t$em, and makin4 sequences
DeEe s$o;n 3ou $o; to make bar p%ots and scatter p%ots ;it$ ectors nd
;eEe s$o;n 3ou $o; treats ectors ;$ere one or more a%ues are not
aai%ab%e
Arror8 unexpected s3mbo% in /Qn t$is/
>
> 5$e ector is Fust t$e Lrst of seera% data structures t$at oPers 7ee 3ou in
t$e next c$apter, ;$ere ;eE%% ta%k aboutX t$e matrix
Arror8 unexpected s3mbo% in /5$e ector/
>
> Gore from Eei%%3
Arror8 unexpected s3mbo% in /Gore from/
>
> Wid 3ou kno; t$at our sponsor Eei%%3 $as some 4reat resources for bi4 data
practitionersV $eck out t$e 7trata Ce;s%etter, t$e 7trata %o4, and 4et access to
Le e-books on bi4 data topics from %eadin4 t$inkers in t$e spaceaS%fsdS%sd%S
Arror8 unexpected s3mbo% in /Wid 3ou/
> datamatrix ratabaris
7/26/2019 akarpersamaankuadrat(latihan r)
38/39
+ rata=sum(x)"%en4t$(x)
+ print(rata)#
> ratabarismatriks
7/26/2019 akarpersamaankuadrat(latihan r)
39/39
1, &&1**'2 &H&&1H2& H21**2 &.*&*H.& &H.IH92
2, &9&*'*2' &H'HI292 *I999 '99H*22 11.HI'
*, *.*1*&I' &2HII.12 *9H*H9& .1&1*1&H '''IH.I
, 1'II..H' H*IH''' -2'.2.&H& &*9'&H&. 'H2I''.
&, 11H*I. .IHI&.I 1I.2*292 HI.H*&1 2'91&9H
', *.H1I2 HH9&'1&. I111&1 9919.9 H9*222
H, .91&29& *H.2** &192**. &19.1H'* '9&.*
9, 2&'I11' 1.*.&.I *1IIH.'I &21*H'& &12.*&
I, .H*.I'2 1.9*'1I* 1..&..''2 &1'22&'2 12*'..I
1., -.11HI19 H2*.*H 2'I...1H &&1'*HH 2*'*''9
11, H9&IH2 1'99I &.9..H*& I&19**I '211H9.
12, 9I.&.'& I'.'.&' 11*H92&&2 &2'HI1' 119*H*'.
1*, &*1*H122 .H21*2 .'''1. '.&1*&' *2.1*2
1, '*99I9. *'9.9. &92&2*& 9.H'9&H& *&'*92.
1&, 2*'29*12 .2&21& '.9I'. 9.&.1.& '19.*2'
1', *HIH99. 2.2*II I'.*&99H &'1&.*. &.&*H
1H, 19&&1' 1H91.1.& &H.&''I* H91&H *2*'.91
19, 22I*12I 9*9I.I1 '992&** 29.**I H&H9..9
1I, .9''..H2 29219I 992I99.* '2.&&1I '99'
2., 1.2H'11' &.2&1*.2 .&.HH99' '.2H1.* '9**2I
> ratabaris
Top Related