x.a <- rnorm(1000, 1, 10)
# 1.1 Filter OUT extreme values out of two standard deviations
# 1.2 Plotting the distribution of the remaining vector x.a
# 1.3 Calculate the 25% 50% and 75% quantile of vector x.a. (You may google "quantile r)
# 1.4 Get the sequence between 25% to 75% of x.a
x.b <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k")
# 2.1 Get only elements at odd positions
# 2.2 Truncate the first 2 elements and the last 2 elements
population <- c(158228, 126687, 228075, 204903, 308383)
town <- c("中正", "大同", "中山", "松山", "大安")
# 3.1 Sort the population,
# the reuslt should be [1] 126687 158228 204903 228075 308383
# 3.2 Sort populations in decreasing order
# (Google it or check help)
# Result: [1] 308383 228075 204903 158228 126687
# 3.3 Sort town names according to population in decreasing order
# Result: [1] "大安" "中山" "松山" "中正" "大同"
# 4.1 Print current time
# e.g., "2019-09-02 21:31:36 CST"
# 4.2 Check the data type of current time
# 4.3 Print today
# e.g., [1] "2019-09-02"
# 4.4 Check the data type of date
# 4.5 Write example to compare following functions: print(), cat(), and message()
# 5.1 Using google to find out how to measure the runing time of the following code
x <- rnorm(10000000, 1, 10)
plot(density(x))
order(df2$a, df2$b)
是先照a
還是b
排序呢?那如果加上負號又是什麼意思呢?a <- c(5, 5, 5, 5, 4, 4, 4, 3, 3, 1, 1, 1, 2, 2, 2)
b <- c(3, 3, 3, 4, 4, 4, 2, 2, 2, 4, 4, 1, 4, 1, 1)
df2 <- data.frame(a, b)
# sort df2 in orders of decreasing b then increasing a
df2 <- df2[order(df2$a, -df2$b),]
country <- c("CN", "US", "JP", "HK", "KR", "SG", "DE", "MY", "VN", "PH", "TH", "AU", "NL", "SA", "ID", "GB", "IN", "FR", "IT", "AE")
import <- c(26.142, 12.008, 7.032, 13.646, 4.589, 5.768, 2.131, 2.802, 3.428, 3.019, 1.976, 1.118, 1.624, 0.449, 0.983, 1.302, 1.027, 0.553, 0.670, 0.455)
export <- c(22.987, 12.204, 11.837, 7.739, 5.381, 4.610, 2.866, 2.784, 2.414, 2.092, 1.839, 1.788, 1.665, 1.409, 1.391, 1.075, 0.974, 0.899, 0.800, 0.728)
df <- data.frame(country, import, export)