moodymudskipper / tb

IN ~PROGRESS my own take on `[.data.frame`
0 stars 0 forks source link

real life examples #40

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

https://twitter.com/hrbrmstr/status/1265296181174943745

Here we'd just do:

xdf %tb>% 
  .[date = asDate(.), ts = anytime(as.numeric(.))]$
  .[order(ts, decreasing = TRUE)[1] ~ s(study, port)), ]
moodymudskipper commented 4 years ago

from : https://stackoverflow.com/questions/21435339/data-table-vs-dplyr-can-one-do-something-well-the-other-cant-or-does-poorly

dplyr

diamonds %>%
  filter(cut != "Fair") %>%
  group_by(cut) %>%
  summarize(
    AvgPrice = mean(price),
    MedianPrice = as.numeric(median(price)),
    Count = n()
  ) %>%
  arrange(desc(Count))

data.table

diamondsDT <- data.table(diamonds)
diamondsDT[
  cut != "Fair", 
  .(AvgPrice = mean(price),
    MedianPrice = as.numeric(median(price)),
    Count = .N
  ), 
  by = cut
][ 
  order(-Count) 
]

or

diamonds %>% 
  data.table() %>% 
  .[cut != "Fair", 
    .(AvgPrice = mean(price),
      MedianPrice = as.numeric(median(price)),
      Count = .N
    ), 
    by = cut
  ] %>% 
  .[order(-Count)]

tb

diamondsDT %tb>% .[
  cut != "Fair", 
  AvgPrice = mean(price), 
  MedianPrice = as.numeric(median(price)), Count = .N, 
  by = cut]$ 
  .[order(-Count),]