# 林薇薇 鄭大世 林大佑 費顧漫
# 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. 加法
# 薪金+花紅
totalSalary <- salary + bonus
print(totalSalary)
Output result:
[1] 10800 11150 15785 16035
2. 減法
# 總薪金 - 花紅
totalSalary <- salary + bonus
totalSalary <- totalSalary - bonus
print(totalSalary)
Output result:
[1] 8500 9800 12500 15000
3. 餘數
# (薪金/花紅) %% 餘數
remain <- salary%%bonus
print(remain)
Output result:
[1] 1600 350 2645 510
4. 大於
# 花紅大於1500
for (i in bonus) {
if ( i > 1500 )
{
print(i)
}
}
Output result:
[1] 2300
[1] 3285
5. For循環
# 把花紅最少加至1500
while (bonus[2] < 1500) {
bonus[1] = 50 + bonus[1]
bonus[2] = 60 + bonus[2]
bonus[3] = 70 + bonus[3]
bonus[4] = 80 + bonus[4]
}
print(bonus)
Output result:
[1] 2450 1530 3495 1275