tpemartin / 110-1-r4ds-main

MIT License
3 stars 73 forks source link

Exercise 5.2 Regarding the drug data from Exercise 4.8. #61

Open tpemartin opened 2 years ago

tpemartin commented 2 years ago

Exercise 5.2 Regarding the drug data from Exercise 4.8.

  1. For each kind of drug (毒品品項), what was the average amount of drug (the mean of 數量(淨重)_克) found?

  2. Add a column date to the data frame which is a date class created from the column 發生日期

For the following question, we only consider those 毒品品項 that contains the words “安非他命”.

  1. For each year, what was the total amount found? (Apply lubridate::year() to date column will get you year)
raychiu135 commented 2 years ago

https://github.com/raychiu135/110-1-r4ds-main/blob/1aacde81ce85e8f95755bbaafa36f6087945dc8f/exercise_5.2.rmd#L2

linttttt commented 2 years ago

https://github.com/linttttt/110-1-r4ds-main/blob/cb45474eccfffc9a65a949f6e1116bb414492c91/studyCH5(EX).Rmd#L52

AmyChen20021003 commented 2 years ago

https://github.com/AmyChen20021003/110-1-r4ds-main/blob/b18520f271bd64c0872d2904cf06151f393bc8c9/5-2.Rmd#L13

tpemartin commented 2 years ago

@raychiu135, @AmyChen20021003 Please check:

@raychiu135

@linttttt

for(.x in seq_along(pickDate)){
  drug$data$date[[.x+1]] <- pickDate[[.x]]
}

is the same as

# since length(pickDate) == 14823
drug$data$date[2:14824] <- pickDate[1:14823]
# Or
drug$data$date[seq_along(pickDate)+1] <- pickDate[seq_along(pickDate)]

@AmyChen20021003

stone05261234 commented 2 years ago

https://github.com/stone05261234/110-1-r4ds-main/blob/ef877461e73c44efcb72a6d8d3833206679bae4c/5.2#L1