使用函式(2)
本練習屬於課程
R 中級
練習說明
- 計算
linkedin與facebook的元素相加後的平均值,並將結果存成變數avg_sum。 - 再計算一次平均值,但這次將
trim引數設為 0.2,並將結果指定給avg_sum_trimmed。 - 列印
avg_sum與avg_sum_trimmed;你看得出差異嗎?
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# The linkedin and facebook vectors have already been created for you
linkedin <- c(16, 9, 13, 5, 2, 17, 14)
facebook <- c(17, 7, 5, 16, 8, 13, 14)
# Calculate the mean of the sum
# Calculate the trimmed mean of the sum
# Inspect both new variables