[,1][.2]
y `= [,1] 1 5
[,2] 2 6
2 * y + 1
y `= [,1] 3 11
[,2] 5 13
y %*% Y
y `= [,1] 11 35
[,2] 14 46
outer(x[,1], x[,1])
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
rbind(x[1,], x[1,])
rbindは縦に結合
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 1 5 9 13 17
cbind(x[1,], x[1,])
L = list(name = ‘John’, age=55, no.children=2, children.ages = c(15, 18))
names(L) name age no.children children.ages
L[[2]] 55
L$name John
L[‘name’] John
L$children.ages[2]
L[[4]][2]
names(R) = c(“NAME”, “AGE”, “SALARY”)
if-Else
a = 10; b = 5; c = 1
if (a < b){
d = 1
} else if (a == b){
d = 2
} else {
d = 3
}
print(d)
R for loop
total = function(n){
sum = 0
for(i in 1:100){
sum = sum + i
}
print(sum)
return(sum)
}
total(100)
total = function(n){
sum = 5050
num = n
repeat {
sum = sum - num
num = num - 1
if(sum == 0)break
}
return(sum)
}
total = function(){
sum = 0
a = 1
b = 10
while (a