• R语言已解决
  • 【已解决】对数据框中满足某些条件的数据的重写

Liechi

其实hadley大人做了个实验性的dtplyr作为data.table的前端,干的事情是将dplyr的语法翻译到data.table,不过readme里写的也是心酸:都木有什么人用…

This is a large change that breaks all existing uses of dtplyr. But frankly, dtplyr was pretty useless before because it did such a bad job of generating data.table code. Fortunately few people used it, so a major overhaul possible.

我个人的理解是dplyr的性能应付日常操作足够了,真正在乎性能的用户都喜欢折腾,学个data.table也不是啥难事吧

21 天 后

Liechi data.table是不是有更简单的写法

library(data.table)
df <- as.data.table(mtcars)
df[2:5,cyl:=.(ifelse(cyl<6,2,cyl))]
1 年 后

一年后,我用上了 data.table,写在这里给自己当做笔记,这是一个添加旬并且根据平闰年修改旬的日天数的代码:

time_seq <- qxun_sby[, c(1:3, 5)] %>% 
  .[, days := rep(c(10, 10, 11, 10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 11, 
                    10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 8, 10, 10, 11, 10, 10, 10),
                  times = iter / 36)] %>% 
  .[((y %% 100 == 0 & y %% 400 == 0) | (y %% 4 == 0 & y %% 100 != 0)) & t == 30, days := 9]