data.table + dplyr = dtplyr
We only need use lazy_dt()
to transform our data in advance, then use dplyr expression as usual, and then get results by as.data.table()
or as.data.frame()
or as_tibble()
.
library(data.table)
## data.table 1.14.2 using 6 threads (see ?getDTthreads). Latest news: r-datatable.com
## **********
## 用中文运行data.table。软件包只提供英语支持。当在在线搜索帮助时,也要确保检查英语错误信息。这个可以通过查看软件包源文件中的po/R-zh_CN.po和po/zh_CN.po文件获得,这个文件可以并排找到母语和英语错误信息。
## **********
##
## 载入程辑包:'data.table'
## The following objects are masked from 'package:lubridate':
##
## hour, isoweek, mday, minute, month, quarter, second, wday,
## week, yday, year
## The following objects are masked from 'package:dplyr':
##
## between, first, last
## The following object is masked from 'package:purrr':
##
## transpose
## The following objects are masked from 'package:reshape2':
##
## dcast, melt
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
mtcars2 <- lazy_dt(mtcars)
mtcars2 %>%
filter(wt < 5) %>%
mutate(l100k = 235.21 / mpg) %>% # liters / 100 km
group_by(cyl) %>%
summarise(l100k = mean(l100k)) %>%
as_tibble()
## # A tibble: 3 x 2
## cyl l100k
## <dbl> <dbl>
## 1 4 9.05
## 2 6 12.0
## 3 8 14.9
Details please click below links:
dplyr also has other two backends: