เมทริกซ์ — เวกเตอร์ 2 มิติ

R เบื้องต้นสำหรับการเงิน

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

สร้างเมทริกซ์

my_matrix <- matrix(c(2, 3, 4, 5), nrow = 2, ncol = 2)
my_matrix
     [,1] [,2]
[1,]    2    4
[2,]    3    5
my_matrix2 <- matrix(c(2, 3, 4, 5), nrow = 2, ncol = 2,
                     byrow = TRUE)
my_matrix2
     [,1] [,2]
[1,]    2    3
[2,]    4    5
R เบื้องต้นสำหรับการเงิน

การแปลงชนิดข้อมูลในเมทริกซ์

coerce_me <- matrix(c(2, 3, 4, "hi"), nrow = 2, ncol = 2)

coerce_me
    [,1] [,2]
[1,] "2"  "4" 
[2,] "3"  "hi"
R เบื้องต้นสำหรับการเงิน

cbind( ) และ rbind( )

micr <- c(59.20, 59.25, 60.22, 59.95)
ebay <- c(17.44, 18.32, 19.11, 18.22)
cbind(micr, ebay)
      micr  ebay
[1,] 59.20 17.44
[2,] 59.25 18.32
[3,] 60.22 19.11
[4,] 59.95 18.22
rbind(micr, ebay)
 [,1]  [,2]  [,3]  [,4]
59.20 59.25 60.22 59.95
17.44 18.32 19.11 18.22
R เบื้องต้นสำหรับการเงิน

cor()relation

  • +1: ความสัมพันธ์เชิงเส้นบวกสมบูรณ์
  • -1: ความสัมพันธ์เชิงเส้นลบสมบูรณ์
  • 0: ไม่มีความสัมพันธ์เชิงเส้น

ch2_vid3_slides.015.png

R เบื้องต้นสำหรับการเงิน

cor()relation

micr <- c(59.20, 59.25, 60.22, 59.95)
ebay <- c(17.44, 18.32, 19.11, 18.22)

cor(micr, ebay)
0.7835704
micr_ebay_matrix <- cbind(micr, ebay)
cor(micr_ebay_matrix)
          micr      ebay
micr 1.0000000 0.7835704
ebay 0.7835704 1.0000000
R เบื้องต้นสำหรับการเงิน

มาฝึกกันเถอะ!

R เบื้องต้นสำหรับการเงิน

Preparing Video For Download...