Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
2020 1 30
1 2
2 2
3 2
3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 4
4.1 . . . . . . ...
2
1
•
•
• logical, numeric, complex, character
•
•
•
2
R #
#
> #################
> ##
> #################
> cat("ABC") #
A...
3.1 2
> 2^3 # ^
[1] 8
> 2**3 # * 2
[1] 8
> 2^3*4 #
[1] 32
> 2^(3*4)
[1] 4096
> 2**3*4 # ** *
[1] 32
> 2**(3*4)
[1] 4096
> ...
2
•
4
4.1
•
• 0 1 0 1
•
=⇒
• R mode
4.2 R mode
• logical : TRUE FALSE
T F
• numeric : R numeric
• complex : i
• character ...
4.3 2
is. ()
> is.character(" ")
[1] TRUE
> is.numeric(" ")
[1] FALSE
> is.numeric(3.14)
[1] TRUE
> is.numeric(pi)
[1] TRU...
4.5 2
> is.numeric(x)
[1] FALSE
> is.null(x) # NULL
[1] TRUE
> mode(x) # NULL mode "NULL"
[1] "NULL"
> x <- FALSE # x
> is...
5.1 2
• list :
• data.frame : 2
mode
3
5.1
•
•
• vector, matrix, array, list
•
6
6.1
c() c() combine 1
> c(1, 2, 3, 4) #
[...
6.3 2
> rep(1, 5)
[1] 1 1 1 1 1
> rep(" ", 3)
[1] " " " " " "
> rep(TRUE, 3)
[1] TRUE TRUE TRUE
> rep(c(1, 2), 3) #
[1] 1 ...
6.4 2
> x[10]
[1] 10
[]
> days <- c(" ", " ", " ", " ", " ", " ", " ")
> days
[1] " " " " " " " " " " " " " "
> days[3]
[1...
6.5 2
[28] 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
> y <- 50:1 # seq(50, 1)
> y
[1] 50 49 48 ...
2
7
rep()
> help(rep)
standard deviation help.search()
> help.serach("standard deviation")
stats::sd stats
sd() help(sd)
R...
2
> rep(seq(2, 10, 2), 100)
(3) sd() 2
> sd(rep(seq(2, 10, 2), 10))
[1] 2.857143
> sd(rep(seq(2, 10, 2), 100))
[1] 2.83126...
Upcoming SlideShare
Loading in …5
×

of

第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 1 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 2 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 3 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 4 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 5 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 6 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 7 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 8 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 9 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 10 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 11 第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き) Slide 12
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

1 Like

Share

Download to read offline

第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)

Download to read offline

西南学院大学経済学部 演習1 解答付き講義ノート
講義ページ: http://courses.wshito.com/semi1/2020-datascience/index.html

第2回 基本演算,データ型の基礎,ベクトルの操作方法(解答付き)

  1. 1. 2020 1 30 1 2 2 2 3 2 3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 4 4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.2 R mode . . . . . . . . . . . . . . . . . . . . . . . . 4 4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.4 NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 5 6 5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 6 7 6.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 6.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 6.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 6.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 6.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 7 11 7.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 8 11 1
  2. 2. 2 1 • • • logical, numeric, complex, character • • • 2 R # # > ################# > ## > ################# > cat("ABC") # ABC 3 > 3 * 4 [1] 12 > 3 * 4 + 2 [1] 14 > 3 * (4 + 2) [1] 18 > 3/4 [1] 0.75 > -5 / -6 [1] 0.8333333 > (-5)/(-6) [1] 0.8333333 2 I 2
  3. 3. 3.1 2 > 2^3 # ^ [1] 8 > 2**3 # * 2 [1] 8 > 2^3*4 # [1] 32 > 2^(3*4) [1] 4096 > 2**3*4 # ** * [1] 32 > 2**(3*4) [1] 4096 > sqrt(2) [1] 1.414214 > 2^(1/2) [1] 1.414214 log(2) log(2)= loge 2 = ln 2 log(100,10)= log10 100 > log(2) [1] 0.6931472 > log(100, 10) [1] 2 > exp(1) [1] 2.718282 > exp(0.6931472) [1] 2 absolute values > abs(-0.2) [1] 0.2 > abs(0.2) [1] 0.2 3.1 • • • I 3
  4. 4. 2 • 4 4.1 • • 0 1 0 1 • =⇒ • R mode 4.2 R mode • logical : TRUE FALSE T F • numeric : R numeric • complex : i • character : mode() mode mode() > mode(TRUE) [1] "logical" > mode(FALSE) [1] "logical" > mode(pi) # pi [1] "numeric" > mode(2.0) [1] "numeric" > mode(2) [1] "numeric" > mode(2+2i) [1] "complex" > mode(" ") [1] "character" I 4
  5. 5. 4.3 2 is. () > is.character(" ") [1] TRUE > is.numeric(" ") [1] FALSE > is.numeric(3.14) [1] TRUE > is.numeric(pi) [1] TRUE > is.logical(FALSE) [1] TRUE > is.logical(1) [1] FALSE 4.3 ’<-’ > x <- 3 # x 3 > x # [1] 3 > is.numeric(x) # x [1] TRUE > y <- " " > y [1] " " > is.character(y) [1] TRUE > is.numeric(x) [1] TRUE > mode(y) [1] "character" 4.4 NULL • 0 1 0 NULL • R NULL > x <- NULL # NULL > x # x NULL NULL I 5
  6. 6. 4.5 2 > is.numeric(x) [1] FALSE > is.null(x) # NULL [1] TRUE > mode(x) # NULL mode "NULL" [1] "NULL" > x <- FALSE # x > is.null(x) # NULL [1] FALSE > is.logical(x) [1] TRUE > mode(x) [1] "logical" 4.5 • • mode • • logical numeric complex character • mode() • is. () • • NULL 5 1 R • vector : mode 1 1 • matrix : mode 2 • array : mode n I 6
  7. 7. 5.1 2 • list : • data.frame : 2 mode 3 5.1 • • • vector, matrix, array, list • 6 6.1 c() c() combine 1 > c(1, 2, 3, 4) # [1] 1 2 3 4 > c(1, 2, c(3, 4)) # [1] 1 2 3 4 > v <- c("a", "b", "c") # > v # v [1] "a" "b" "c" > c(v, v, c(1, 2, 3)) # [1] "a" "b" "c" "a" "b" "c" "1" "2" "3" 6.2 replicate rep(x, times) x times I 7
  8. 8. 6.3 2 > rep(1, 5) [1] 1 1 1 1 1 > rep(" ", 3) [1] " " " " " " > rep(TRUE, 3) [1] TRUE TRUE TRUE > rep(c(1, 2), 3) # [1] 1 2 1 2 1 2 rep() sequence seq(from, to, by) from to by by 1 > seq(1, 10) [1] 1 2 3 4 5 6 7 8 9 10 > seq(1, 10, 2) # 2 [1] 1 3 5 7 9 > seq(10, 1) [1] 10 9 8 7 6 5 4 3 2 1 > seq(10, 1, -2) [1] 10 8 6 4 2 6.3 [1] > seq(1, 50) [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [28] 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 > 1 [1] 1 1 1 [] > x <- 1:10 > x [1] 1 2 3 4 5 6 7 8 9 10 > x[1] [1] 1 > x[2] [1] 2 I 8
  9. 9. 6.4 2 > x[10] [1] 10 [] > days <- c(" ", " ", " ", " ", " ", " ", " ") > days [1] " " " " " " " " " " " " " " > days[3] [1] " " > days[c(1, 2, 3)] [1] " " " " " " > days[1:3] [1] " " " " " " > days[seq(2, 7, 2)] # 2 1 1 [1] " " " " " " > days[-3] # 3 [1] " " " " " " " " " " " " > days[-1:-3] # 1 3 [1] " " " " " " " " > days[-seq(2, 7, 2)] # seq(2,7,2) c(2,4,6) [1] " " " " " " " " length() > length(days) [1] 7 > length(x) [1] 10 6.4 1 1 R 1 50 : 1:50 seq(1,50) 1 > x <- 1:50 # seq(1, 50) > x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 I 9
  10. 10. 6.5 2 [28] 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 > y <- 50:1 # seq(50, 1) > y [1] 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 [28] 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 > x * 2 # 2 [1] 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 [21] 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 [41] 82 84 86 88 90 92 94 96 98 100 > x / 2 # 2 [1] 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 [17] 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0 [33] 16.5 17.0 17.5 18.0 18.5 19.0 19.5 20.0 20.5 21.0 21.5 22.0 22.5 23.0 23.5 24.0 [49] 24.5 25.0 > x + 100 # 100 [1] 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 [21] 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 [41] 141 142 143 144 145 146 147 148 149 150 > x + y # x y [1] 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 [28] 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 > log(1:5) # log(c(1, 2, 3, 4, 5)) log [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 > (1:5)^2 # c(1, 2, 3, 4, 5)^2 [1] 1 4 9 16 25 (1:5)^2 1:5 2 1:5^2 1 52 = 25 > 1:5^2 # 1:25 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 6.5 • : • c() rep() seq() • • length() I 10
  11. 11. 2 7 rep() > help(rep) standard deviation help.search() > help.serach("standard deviation") stats::sd stats sd() help(sd) R source R source help.search() 7.1 • help() • help.search() • • sd() 8 (1) 2, 4, 6, 8, 10 10 [1] 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 [26] 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 > rep(seq(2, 10, 2), 10) (2) 2, 4, 6, 8, 10 100 I 11
  12. 12. 2 > rep(seq(2, 10, 2), 100) (3) sd() 2 > sd(rep(seq(2, 10, 2), 10)) [1] 2.857143 > sd(rep(seq(2, 10, 2), 100)) [1] 2.83126 I 12
  • JinseiHamamoto

    Mar. 12, 2020

西南学院大学経済学部 演習1 解答付き講義ノート 講義ページ: http://courses.wshito.com/semi1/2020-datascience/index.html

Views

Total views

377

On Slideshare

0

From embeds

0

Number of embeds

0

Actions

Downloads

17

Shares

0

Comments

0

Likes

1

×