B 5 (2) VBAR / B 5 (2014 11 17 ) / 34
VBA VBA (Visual Basic for Applications) Visual Basic VBAVisual Basic Visual BasicC B 5 (2014 11 17 ) 1 / 34
VBA 2 Excel.xlsm 01 Sub test() 02 Dim tmp As Double 03 tmp = Worksheets("Sheet1").Range("C4").Value 04 tmp = tmp * tmp 05 Range("E4").Value = tmp 06 Range("F4").Value = "=POWER(C4,2)" 07 MsgBox(": =" + CStr(tmp)) 08 End Sub test B 5 (2014 11 17 ) 2 / 34
VBA 0108Subtest 1test 02 Double tmp Dim As Doubletmp Dim As As B 5 (2014 11 17 ) 3 / 34
VBA 03Sheet1C4tmp = "" 04tmp2tmp 05E4tmpE4 B 5 (2014 11 17 ) 4 / 34
VBA 06 F4 "=POWER(C4,2)" 07 ": =" + CStr(tmp) +"AB"+"CD""ABCD" CStr() B 5 (2014 11 17 ) 5 / 34
VBA VBA 02 Dim tmp As Double 02 dim tmp as double "a" "A" B 5 (2014 11 17 ) 6 / 34
VBA : Integer : 2 15 2 15 Long : 2 31 2 31 Currency : 2 63 2 63 Single : 106 Double : 1015 String : Boolean : TrueFalse Variant : B 5 (2014 11 17 ) 7 / 34
VBA : + : 3+47 - : 3-4-1 * : 3*412 / : 3/41 \ (or ) : 3\40 Mod : 8 Mod 32 ^ : 3^23 2 9 () B 5 (2014 11 17 ) 8 / 34
VBA () IfElseIfElseEnd If 01 If A Then 02 A 03 ElseIf B Then 04 AB 05 ElseIf C Then 06 A, BC 07 Else 08 A, B, C 09 End If ElseIf0Else B 5 (2014 11 17 ) 9 / 34
VBA () A = B : ABTrue= A < B : ABTrue A > B : ABTrue A <= B : ABTrue A >= B : ABTrue A <> B : ABTrue A And B : ABTrueTrue A Or B : ABTrue True Not A : ATrueTrue B 5 (2014 11 17 ) 10 / 34
VBA (For) ForForNext 01 For = To Step 02 03 Next Step 1 B 5 (2014 11 17 ) 11 / 34
VBA (For) 01 Dim i As Integer 02 For i = 3 To 10 Step 2 03 (i=3, 5, 7, 94) 04 Next 01 Dim i As Integer 02 For i = 1 To 5 03 (i=1, 2, 3, 4, 55) 04 Next 01 Dim i As Integer 02 For i = 10 To 3 Step -3 03 (i=10, 7, 43) 04 Next B 5 (2014 11 17 ) 12 / 34
VBA (For) ForExit For 01 Dim i As Integer 02 For i = 3 To 10 Step 2 03 If i = 7 Then 04 Exit For i=7for 05 End If 06 (i=3, 52) 07 Next B 5 (2014 11 17 ) 13 / 34
VBA (Do) DoLoopExit Do 01 Dim i As Integer 02 i = 1 03 Do 04 (i=1, 2, 3, 44) 05 i = i + 1 06 If i = 5 Then 07 Eixt Do 08 End If 09 Loop B 5 (2014 11 17 ) 14 / 34
VBA (Do, While) DoLoop While 01 Dim i As Integer 02 i = 1 03 Do While i < 5 04 (i=1, 2, 3, 44) 05 i = i + 1 06 Loop 01 Dim i As Integer 02 i = 10 03 Do While i < 5 04 (1) 05 i = i + 1 06 Loop B 5 (2014 11 17 ) 15 / 34
VBA CInt : Integer CLng : Long CSng : Single CDbl : Double CStr : String B 5 (2014 11 17 ) 16 / 34
VBA 1 Dim () As (0)(1)...()+1 01 Dim i As Integer 02 Dim arr(5) As Integer 03 For i = 0 To 5 04 arr(i) = i * i 05 Next arr(0) 0 arr(3) 9 arr(5) 25 B 5 (2014 11 17 ) 17 / 34
VBA 01 Dim i As Integer 02 Dim arr(5) As Integer 01 Dim i As Integer, arr(5) As Integer 01 Dim i, arr(5) As Integer ivariant B 5 (2014 11 17 ) 18 / 34
VBA Worksheets("Sheet1").Range("C4").Value Worksheets("Sheet1").Cells(4,3).Value C4Worksheets("Sheet1"). B 5 (2014 11 17 ) 19 / 34
VBA (SubFunction) Sub A B QR QR 2 QR A B 2 B 5 (2014 11 17 ) 20 / 34
VBA Sub FunctionSub 01 Sub Kaku(n As Long) 02 Dim i As Long 03 For i = 1 To n 04 Cells(i, 1) = 0 05 Next 06 End Sub Call Kaku(5) Kaku 5 150 B 5 (2014 11 17 ) 21 / 34
VBA 01 Function MySum(n As Long) 02 Dim i As Long, s As Long 03 s = 0 04 For i = 1 To n 05 s = s + i 06 Next 07 MySum = s 08 End Function n = MySum(5)n1+2+3+ 4 + 515 B 5 (2014 11 17 ) 22 / 34
VBA B 5 (2014 11 17 ) 23 / 34
R R GUI B 5 (2014 11 17 ) 24 / 34
Excel PC VBA SAS C B 5 (2014 11 17 ) 25 / 34
breakelseforfunctionifinnextrepeat returnwhiletruefalse <-->=assign<- x <- 1 x1 +-*/**^ 2/3 0.6666667 2**4 16 B 5 (2014 11 17 ) 26 / 34
(2,4,7) y y <- c(2, 4, 7) c(2, 4, 7) + c(5, 4, 3) (7,8,10) c(2, 4, 7) * c(5, 4, 3) (10,16,21) c(1,2,3,4,5,6) + c(100,1000) (101,1002,103,1004,105,1006) c(1,2,3,4,5,6,7) + c(100,1000) B 5 (2014 11 17 ) 27 / 34
1 c(1, 2, 3, 4) * 2 (2,4,6,8) c(1, 2, 3, 4) + 2 (3,4,5,6) c(1, 2, 3, 4) ** 2 (1,4,9,16) c(2:6)c(2,3,4,5,6)xlength(x) xkx[k]1 24x[2:4]x yappend(x,y)x3 x[x>3]5x 24x[c(FALSE,TRUE,FALSE,TRUE,FALSE)] B 5 (2014 11 17 ) 28 / 34
matrix(, nrow=, ncol=, byrow=true) (1,1) (1,2) byrow=false %*% x 2 x[2,]2 x[,2] xapply(mean, 1, x) apply(mean, 2, x) B 5 (2014 11 17 ) 29 / 34
> x <- matrix(c(1,2,3,4),nrow=2,ncol=2,byrow=true) > x [,1] [,2] [1,] 1 2 [2,] 3 4 > y <- matrix(c(2,3,4,5),nrow=2,ncol=2,byrow=true) > x * y [,1] [,2] [1,] 2 6 [2,] 12 20 > x %*% y [,1] [,2] [1,] 10 13 [2,] 22 29 B 5 (2014 11 17 ) 30 / 34
read.table read.table x <- read.table("hoge.txt") hoge.txt x x <- read.table("hoge.csv", header=true, sep=",") header=true1sep="," csv read.csv 2 B 5 (2014 11 17 ) 31 / 34
if(){ }else if(){ }else if(){ }else{ } B 5 (2014 11 17 ) 32 / 34
for for for( in ){ } () i1 100 for(i in c(1:100)){ } B 5 (2014 11 17 ) 33 / 34
<- function(){ } return() BMI BMI <- function(h, w){ return( w/((h/100)^2) ) } BMI(170,60) 20.76125 B 5 (2014 11 17 ) 34 / 34