[英]Downsampling analytics data in MySQL or in R
我將分析數據作為帶有時間戳和一些數據的表存儲在MySQL數據庫中,並希望對此數據進行下采樣(即,在一個時間范圍內對其進行分組)(通過計算條目數)以顯示在管理控制台上,以及我想知道使用R腳本選擇數據並對其進行下采樣會更有效,還是使用起來會更好
GROUP BY UNIX_TIMESTAMP(timestamp) DIV <some time>
並在數據庫層上進行。 任何其他技巧也將不勝感激。
如果可以使用dplyr
,則可以執行以下操作:
library(dplyr)
yay <-
# Specify username and password in my.cnf
src_mysql(host = "blah.com") %>%
tbl("some_table") %>%
# You will need to compute a grouping variable
mutate(group = unix_timestamp(timestamp)) %>%
group_by(group) %>%
# This will return the number of rows in each group
summarise(n = n()) %>%
# This will execute the query and return a data.frame
collect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.