
R Markdown 文件的常用語法
==============================

## 1. 字型大小：
# 網絡分析
## 網絡分析
### 網絡分析
#### 網絡分析
##### 網絡分析
###### 網絡分析

## 2. 文句強調：
### *斜體* and **粗體**

## 3. 條列語句：
### Network data analysis:
* #### Ego-network
* #### Centrality measures
* #### Group and community structures
* #### Positions and role analysis
* #### Network-level indices

## 4. 表格：
第一組 | 第二組| 第三組| 第四組| 第五組
-------|-------|-------|-------|-------
樣本1  | 樣本2 | 樣本3 | 樣本4 | 樣本5
樣本6  | 樣本7 | 樣本8 | 樣本9 | 樣本10

## 5. 上標與下標：
### 單位：km^2^
### 水分子：H~2~O is a liquid.

## 6. 分隔線：
***

## 7. 插入 R Code Chuncks：
### **作業一 (A Short Introduction to R)**  
### ToDo 1
```{r}
(2014 - 2009) / (2014 - 1991) * 100
```

### ToDo 2
```{r}
a = (2014 - 2009) / (2014 - 1991) * 100
a
```

### ToDo 3
```{r}
b = c(4,5,8,11)
sum(b)

x = rnorm(100)
plot(x)
```

### ToDo 4: Help and documentation
```{r}
help(sqrt)
```

### ToDo 5: Scripts
```{r}
setwd("D:/R_Labs/rmd_demo")
source("firstscript.R")
```

### ToDo 6: Data structures
```{r}
p = 31:60
Q = matrix(data=p, nrow = 6)

x1 = rnorm(100)
x2 = rnorm(100)
x3 = rnorm(100)
t = data.frame(a=x1,b=x1+x2,c=x1+x2+x3)
plot(t)
sd(as.numeric(unlist(t)))
```

### ToDo 7: Graphic
```{r}
plot(t$a, type="l", ylim=range(t),lwd=3, col=rgb(1,1,0,0.7))
lines(t$b, type="s", lwd=2,col=rgb(0.3,0.4,0.3,0.9))
points(t$c, pch=22, cex=2,col=rgb(0,0,1,0.3))
```

### ToDo 8: Reading and writing data files
```{r}
setwd("D:/R_Labs/rmd_demo")
d = read.table(file="tst1.txt",header = TRUE)
d$g = d$g * 5
write.table(d,file="tst2.txt",row.names=FALSE)

```

### ToDo 9: Not available data
```{r}
mean(sqrt(rnorm(100)))
```

### ToDo 10: Classes
```{r}
data1 = c(strptime(c("20141205","20150612"),format="%Y%m%d"))
data2 = c(100,90)
plot(data1,data2, xlab = "Date",ylab="Count",main = "The number of presents I expected.")
```

### ToDo 11: Programming tools
```{r}
s = 1:100
for(i in 1:100)
{
  if (s[i] < 5 | s[i] > 90)
  {
    s[i] = s[i] * 10
  } else
  {
    s[i] = s[i] * 0.1
  }
}
s

k=1:10
fun = function(arg1)
{
  l = length(arg1)
  for(i in 1:l)
  {
    if (arg1[i] < 5 | arg1[i] > 90)
    {
      arg1[i] = arg1[i] * 10
    } else
    {
      arg1[i] = arg1[i] * 0.1
    }
  }
  return (arg1)
}
fun(arg1=k)
k
```

