# 林薇薇 鄭大世 林大佑 費顧漫
# 8500 9800 12500 15000
# 採購員 主任 經理 總裁
# 2300 1350 3285 1035
userName <- c("Lam Wei Wei", "Zheng Da Shi", "Lin Da You", "Fei Gu Man")
salary <- c(8500, 9800, 12500, 15000)
jobPosition <- c("Staff", "Manger", "BOSS", "CEO")
bonus <- c(2300, 1350, 3285, 1035)
1. Seq
# 由一個數到另一個數, 32~44
print(seq(32,44))
Output result:
[1] 32 33 34 35 36 37 38 39 40 41 42 43 44
2. Mean
# 平均值
meanSalary <-mean(salary)
print(meanSalary)
Output result:
[1] 11450
3. Sum
# 總值
sumSalary <-sum(salary)
print(meanSalary)
Output result:
[1] 45800
4. Create function
# 創建function。 i附值i、當i少於salary.length、totalSalary++
sumSalary <- function() {
totalSalary = 0
for ( i in 1: length(salary))
{
totalSalary <- totalSalary + salary[i]
}
print(totalSalary)
}
sumSalary()
Output result:
[1] 45800
R叁考网站
http://www.cyclismo.org/tutorial/R/index.html