R version 3.6.
1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (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.
Natural language support but running in an English locale
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.
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_MONETARY failed, using "C"
[R.app GUI 1.70 (7684) x86_64-apple-darwin15.6.0]
WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work.
Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system preferences
accordingly.
[Workspace restored from /Users/alfizidasyukron/.RData]
[History restored from /Users/alfizidasyukron/.Rapp.history]
> # 75 numbers between 0 and 10 of uniform distribution
> x <- runif(75, 0, 10)
> x <- sort(x)
> y <- 200 + x^3 - 10 * x^2 + x + rnorm(75, 0, 20)
> lr <- lm(y ~ x) # linear regression
> poly <- loess(y ~ x) # LOESS
> 3.2 Exploratory Data Analysis 93
Error: unexpected symbol in "3.2 Exploratory"
> fit <- predict(poly) # fit a nonlinear line
> plot(x,y)
> # draw the fitted line for the linear regression
> points(x, lr$coefficients[1] +
+ lr$coefficients[2] * x,
+ type = "l", col = 2)
> data(mtcars)
> dotchart(mtcars$mpg,labels=row.names(mtcars),cex=.7,
+ main="Miles Per Gallon (MPG) of Car Models",
+ xlab="MPG")
> barplot(table(mtcars$cyl), main="Distribution of Car Cylinder Counts",
+ xlab="Number of Cylinders")
> dotchart(mtcars$mpg,labels=row.names(mtcars),cex=.7,
+ main="Miles Per Gallon (MPG) of Car Models",
+ xlab="MPG")
> xvc=data(mtcars)
> xvc
[1] "mtcars"
> dotchart(mtcars$mpg,labels=row.names(mtcars),cex=.7,
+ main="Miles Per Gallon (MPG) of Car Models",
+ xlab="MPG")
> # sort by mpg
> cars <- mtcars[order(mtcars$mpg),]
> # grouping variable must be a factor
> cars$cyl <- factor(cars$cyl)
> cars$color[cars$cyl==4] <- "red"
> cars$color[cars$cyl==6] <- "blue"
> cars$color[cars$cyl==8] <- "darkgreen"
> dotchart(cars$mpg, labels=row.names(cars), cex=.7, groups= cars$cyl,
+ main="Miles Per Gallon (MPG) of Car Models\nGrouped by Cylinder",
+ xlab="Miles Per Gallon", color=cars$color, gcolor="black")
> library(ggplot2)
Error in library(ggplot2) : there is no package called 'ggplot2'
> # plot the jittered scatterplot w/ boxplot
> # color-code points with zip codes
> # the outlier.size=0 prevents the boxplot from plotting the outlier
> ggplot(data=DF, aes(x=as.factor(Zip1), y=log10(MeanHouseholdIncome))) +
+ geom_point(aes(color=factor(Zip1)), alpha=0.2, position="jitter") +
+ geom_boxplot(outlier.size=0, alpha=0.1) +
+ guides(colour=FALSE) +
+ ggtitle ("Mean Household Income by Zip Code")
Error in ggplot(data = DF, aes(x = as.factor(Zip1), y = log10(MeanHouseholdIncome))) :
could not find function "ggplot"
Error in if (res > nrow(m)) { : argument is of length zero
--- Please select a CRAN mirror for use in this session ---
Error in if (res > nrow(m)) { : argument is of length zero
Error in if (res > nrow(m)) { : argument is of length zero
--- Please select a CRAN mirror for use in this session ---
Error in if (res > nrow(m)) { : argument is of length zero
Error in if (res > nrow(m)) { : argument is of length zero
--- Please select a CRAN mirror for use in this session ---
Error in if (res > nrow(m)) { : argument is of length zero
starting httpd help server ... done
> sort by mpg
Error: unexpected symbol in "sort by"
> cars <- mtcars[order(mtcars$mpg),]
> # grouping variable must be a factor
> cars$cyl <- factor(cars$cyl)
> cars$color[cars$cyl==4] <- "red"
> cars$color[cars$cyl==6] <- "blue"
> cars$color[cars$cyl==8] <- "darkgreen"
> dotchart(cars$mpg, labels=row.names(cars), cex=.7, groups= cars$cyl,
+ main="Miles Per Gallon (MPG) of Car Models\nGrouped by Cylinder",
+ xlab="Miles Per Gallon", color=cars$color, gcolor="black")
> cars
mpg cyl disp hp drat wt qsec vs am gear carb color
Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 darkgreen
Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 darkgreen
Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 darkgreen
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 darkgreen
Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 darkgreen
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 darkgreen
Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 darkgreen
AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 darkgreen
Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 darkgreen
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 darkgreen
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 darkgreen
Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 darkgreen
Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 blue
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 blue
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 darkgreen
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 blue
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 darkgreen
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 blue
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 blue
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 blue
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 blue
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 red
Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 red
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 red
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 red
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 red
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 red
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 red
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 red
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 red
Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 red
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 red
>
>
> read.csv(file="/Dokumen/datapenyakit.csv"
+)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '/Dokumen/datapenyakit.csv': No such file or directory
> ~/Downloads/datapenyakit2.csv
Error: unexpected '/' in "~/"
> read.csv(file="/Downloads/datapenyakit2.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '/Downloads/datapenyakit2.csv': No such file or directory
> read.csv(file, "/Dokumen/datapenyakit.csv")
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
'file' must be a character string or connection
> read.csv(file, header=TRUE, "/Dokumen/datapenyakit.csv")
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
'file' must be a character string or connection
>
> > library(gdata)
Error: unexpected '>' in ">"
> library(gdata)
Error in library(gdata) : there is no package called 'gdata'
> df <- read.csv('/Downloads/datapenyakit2.csv' header = TRUE)
Error: unexpected symbol in "df <- read.csv('/Downloads/datapenyakit2.csv' header"
> df <- read.csv('/Downloads/datapenyakit2.csv', header = TRUE)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '/Downloads/datapenyakit2.csv': No such file or directory
> df <- read.csv('~/Downloads/datapenyakit2.csv', header = TRUE)
> df
X....Pneumonia.Kusta.Campak
1 ACEH;1129;524;14
2 SUMATERA UTARA;17226;197;80
3 SUMATERA BARAT;15373;54;425
4 RIAU;9552;108;18
5 JAMBI;7114;72;491
6 SUMATERA SELATAN;17254;330;415
7 BENGKULU;1039;17;142
8 LAMPUNG;6942;53;37
9 KEP. BANGKA BELITUNG;7869;35;63
10 KEP. RIAU;859;24;158
11 DKI JAKARTA;39755;317;1209
12 JAWA BARAT;180357;2026;650
13 JAWA TENGAH;36279;1807;-
14 DI YOGYAKARTA;2829;105;37
15 JAWA TIMUR;96087;4013;1072
16 BANTEN;32978;1026;606
17 BALI;5731;61;141
18 NUSA TENGGARA BARAT;24872;292;3
19 NUSA TENGGARA TIMUR;2364;280;
20 KALIMANTAN BARAT;2791;57;254
21 KALIMANTAN TENGAH;408;26;311
22 KALIMANTAN SELATAN;14764;145;
23 KALIMANTAN TIMUR;7828;176;
24 KALIMANTAN UTARA;;41;
25 SULAWESI UTARA;753;427;62
26 SULAWESI TENGAH;10152;494;450
27 SULAWESI SELATAN;2445;1220;836
28 SULAWESI TENGGARA;3262;281;101
29 GORONTALO;4226;223;43
30 SULAWESI BARAT;1532;215;
31 MALUKU;247;211;23
32 MALUKU UTARA;633;544;126
33 PAPUA BARAT;;717;
34 PAPUA;;1084;418
> df <- read.csv('~/Downloads/datapenyakit2.csv', header = TRUE, sep=",")
> df
X....Pneumonia.Kusta.Campak
1 ACEH;1129;524;14
2 SUMATERA UTARA;17226;197;80
3 SUMATERA BARAT;15373;54;425
4 RIAU;9552;108;18
5 JAMBI;7114;72;491
6 SUMATERA SELATAN;17254;330;415
7 BENGKULU;1039;17;142
8 LAMPUNG;6942;53;37
9 KEP. BANGKA BELITUNG;7869;35;63
10 KEP. RIAU;859;24;158
11 DKI JAKARTA;39755;317;1209
12 JAWA BARAT;180357;2026;650
13 JAWA TENGAH;36279;1807;-
14 DI YOGYAKARTA;2829;105;37
15 JAWA TIMUR;96087;4013;1072
16 BANTEN;32978;1026;606
17 BALI;5731;61;141
18 NUSA TENGGARA BARAT;24872;292;3
19 NUSA TENGGARA TIMUR;2364;280;
20 KALIMANTAN BARAT;2791;57;254
21 KALIMANTAN TENGAH;408;26;311
22 KALIMANTAN SELATAN;14764;145;
23 KALIMANTAN TIMUR;7828;176;
24 KALIMANTAN UTARA;;41;
25 SULAWESI UTARA;753;427;62
26 SULAWESI TENGAH;10152;494;450
27 SULAWESI SELATAN;2445;1220;836
28 SULAWESI TENGGARA;3262;281;101
29 GORONTALO;4226;223;43
30 SULAWESI BARAT;1532;215;
31 MALUKU;247;211;23
32 MALUKU UTARA;633;544;126
33 PAPUA BARAT;;717;
34 PAPUA;;1084;418
> read.xlsx('~/Documents/Datapenyakit3.xlsx', header=true)
Error in read.xlsx("~/Documents/Datapenyakit3.xlsx", header = true) :
could not find function "read.xlsx"
> df <- read.csv('~/Downloads/datapenyakit2.csv', header = TRUE, sep=",")
>
> df
X....Pneumonia.Kusta.Campak
1 ACEH;1129;524;14
2 SUMATERA UTARA;17226;197;80
3 SUMATERA BARAT;15373;54;425
4 RIAU;9552;108;18
5 JAMBI;7114;72;491
6 SUMATERA SELATAN;17254;330;415
7 BENGKULU;1039;17;142
8 LAMPUNG;6942;53;37
9 KEP. BANGKA BELITUNG;7869;35;63
10 KEP. RIAU;859;24;158
11 DKI JAKARTA;39755;317;1209
12 JAWA BARAT;180357;2026;650
13 JAWA TENGAH;36279;1807;-
14 DI YOGYAKARTA;2829;105;37
15 JAWA TIMUR;96087;4013;1072
16 BANTEN;32978;1026;606
17 BALI;5731;61;141
18 NUSA TENGGARA BARAT;24872;292;3
19 NUSA TENGGARA TIMUR;2364;280;
20 KALIMANTAN BARAT;2791;57;254
21 KALIMANTAN TENGAH;408;26;311
22 KALIMANTAN SELATAN;14764;145;
23 KALIMANTAN TIMUR;7828;176;
24 KALIMANTAN UTARA;;41;
25 SULAWESI UTARA;753;427;62
26 SULAWESI TENGAH;10152;494;450
27 SULAWESI SELATAN;2445;1220;836
28 SULAWESI TENGGARA;3262;281;101
29 GORONTALO;4226;223;43
30 SULAWESI BARAT;1532;215;
31 MALUKU;247;211;23
32 MALUKU UTARA;633;544;126
33 PAPUA BARAT;;717;
34 PAPUA;;1084;418
> df <- read.csv('~/Downloads/datapenyakit2.csv', header = TRUE, sep=";")
df <- read.csv('~/Documents/Datapenyakitkusta.csv', header = TRUE, sep=";")
~/Documents/Datapenyakitkusta.csv
> df
X... Pneumonia Kusta Campak
1 ACEH 1129 524 14
2 SUMATERA UTARA 17226 197 80
3 SUMATERA BARAT 15373 54 425
4 RIAU 9552 108 18
5 JAMBI 7114 72 491
6 SUMATERA SELATAN 17254 330 415
7 BENGKULU 1039 17 142
8 LAMPUNG 6942 53 37
9 KEP. BANGKA BELITUNG 7869 35 63
10 KEP. RIAU 859 24 158
11 DKI JAKARTA 39755 317 1209
12 JAWA BARAT 180357 2026 650
13 JAWA TENGAH 36279 1807 -
14 DI YOGYAKARTA 2829 105 37
15 JAWA TIMUR 96087 4013 1072
16 BANTEN 32978 1026 606
17 BALI 5731 61 141
18 NUSA TENGGARA BARAT 24872 292 3
19 NUSA TENGGARA TIMUR 2364 280
20 KALIMANTAN BARAT 2791 57 254
21 KALIMANTAN TENGAH 408 26 311
22 KALIMANTAN SELATAN 14764 145
23 KALIMANTAN TIMUR 7828 176
24 KALIMANTAN UTARA NA 41
25 SULAWESI UTARA 753 427 62
26 SULAWESI TENGAH 10152 494 450
27 SULAWESI SELATAN 2445 1220 836
28 SULAWESI TENGGARA 3262 281 101
29 GORONTALO 4226 223 43
30 SULAWESI BARAT 1532 215
31 MALUKU 247 211 23
32 MALUKU UTARA 633 544 126
33 PAPUA BARAT NA 717
34 PAPUA NA 1084 418
> datapenyakit2$Kusta
Error: object 'datapenyakit2' not found
> df$Kusta
[1] 524 197 54 108 72 330 17 53 35 24 317 2026 1807 105 4013
[16] 1026 61 292 280 57 26 145 176 41 427 494 1220 281 223 215
[31] 211 544 717 1084
A
cars <- mtcars[order(mtcars$mpg),]
# grouping variable must be a factor
cars$cyl <- factor(cars$cyl)
cars$color[cars$cyl==4] <- "red"
cars$color[cars$cyl==6] <- "blue"
cars$color[cars$cyl==8] <- "darkgreen"
dotchart(cars$mpg, labels=row.names(cars), cex=.7, groups= cars$cyl,
main="Miles Per Gallon (MPG) of Car ModelsÄnGrouped by Cylinder",
xlab="Miles Per Gallon", color=cars$color, gcolor="black")
jumlah = kusta[order(kusta$Kusta),]
jumlah$Geografi=factor(jumlah$Geografi)
jumlah$color[jumlah$Geografi==”Sumatera”] = ”red”
jumlah$color[jumlah $Geografi==”Jawa”]= ”red”
jumlah$color[jumlah $Geografi==Kalimantan]= ”red”
jumlah$color[jumlah $Geografi==Sulawesi]= ”blue”
jumlah$color[jumlah $Geografi==Nusa Tenggara]= ”blue”
jumlah$color[jumlah $Geografi==Papua]= ”blue”
jumlah$color[jumlah $Geografi==Maluku]= ”blue”