---
# System prepended metadata

title: 迴圈運算
tags: [R教學, 基礎教學]

---

# 迴圈運算
###### tags: `R教學` `基礎教學`

```r=
a <- 1
for(i in 1:3){
  a <- 5+a
}

a <- rep(NA, 100)
for(i in c(1,3,5)){
  a[i] <- i
  a[i+1] <- i
}

a <- 1
while(a<10){ a <-  5 + a}  ##11

a <- 19
ifelse(a<10, b <- 1, b <- 3)

if(a<10)
{b <- 1}else
{b<-3}

m <- matrix(1:25, 5)
m.e <- rep(NA, ncol(m))
for (i in 1:ncol(m)){
  m.e[i] <- mean(m[,i])
}
apply(m, 2, mean) ## µ²ªGµ¥©óm.e 
apply(m, 1, mean)
```