#Vektor
x <- c(20,30,40);x
## [1] 20 30 40
y <- c(100,120,140);y
## [1] 100 120 140
#Data Frame
a <- cbind.data.frame(x,y);a
##    x   y
## 1 20 100
## 2 30 120
## 3 40 140
#Plot
plot(x, y, type="p")

#Input Data
ID <- c(1:10)
NAME <- c("Alex","Cindy","Cici","Kim","Key","Lou","Geo","Jim","Shelly","Dino")
AGE <- c(18,20,25,23,19,22,21,21,24,23)
CLASS <- c(2,4,5,1,2,3,4,5,1,2)
SCORE <- c(8,9,7,8,9,6,5,10,10,10)
data1 <- cbind.data.frame(ID,NAME,AGE,CLASS,SCORE); data1
##    ID   NAME AGE CLASS SCORE
## 1   1   Alex  18     2     8
## 2   2  Cindy  20     4     9
## 3   3   Cici  25     5     7
## 4   4    Kim  23     1     8
## 5   5    Key  19     2     9
## 6   6    Lou  22     3     6
## 7   7    Geo  21     4     5
## 8   8    Jim  21     5    10
## 9   9 Shelly  24     1    10
## 10 10   Dino  23     2    10
#Menghitung jumlah baris
nrow(data1)
## [1] 10
#Menghitung jumlah kolom
ncol(data1)
## [1] 5
#Menghitung dimensi
dim(data1)
## [1] 10  5
#Menghitung statistik ringkasan
summary(data1)
##        ID            NAME                AGE            CLASS    
##  Min.   : 1.00   Length:10          Min.   :18.00   Min.   :1.0  
##  1st Qu.: 3.25   Class :character   1st Qu.:20.25   1st Qu.:2.0  
##  Median : 5.50   Mode  :character   Median :21.50   Median :2.5  
##  Mean   : 5.50                      Mean   :21.60   Mean   :2.9  
##  3rd Qu.: 7.75                      3rd Qu.:23.00   3rd Qu.:4.0  
##  Max.   :10.00                      Max.   :25.00   Max.   :5.0  
##      SCORE      
##  Min.   : 5.00  
##  1st Qu.: 7.25  
##  Median : 8.50  
##  Mean   : 8.20  
##  3rd Qu.: 9.75  
##  Max.   :10.00
#Melihat struktur data
str(data1)
## 'data.frame':    10 obs. of  5 variables:
##  $ ID   : int  1 2 3 4 5 6 7 8 9 10
##  $ NAME : chr  "Alex" "Cindy" "Cici" "Kim" ...
##  $ AGE  : num  18 20 25 23 19 22 21 21 24 23
##  $ CLASS: num  2 4 5 1 2 3 4 5 1 2
##  $ SCORE: num  8 9 7 8 9 6 5 10 10 10
#Menghilangkan kolom nama
data1 <- data1[-2]
sum(data1)
## [1] 382
#Total nilai dari data data1
sum(data1$SCORE)
## [1] 82
sd(data1$AGE)
## [1] 2.221111
median(data1$SCORE)
## [1] 8.5
min(data1$SCORE)
## [1] 5
max(data1$SCORE)
## [1] 10
#Membuat plot
hist(data1$SCORE, main="Plot Histogram", col="green")

boxplot(data1, main="Plot Boxplot", col="yellow")

#Korelasi
cor(data1)
##               ID         AGE       CLASS       SCORE
## ID     1.0000000  0.41306800 -0.13245324  0.29339082
## AGE    0.4130680  1.00000000  0.01969639 -0.00571326
## CLASS -0.1324532  0.01969639  1.00000000 -0.28312696
## SCORE  0.2933908 -0.00571326 -0.28312696  1.00000000

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.