這個什麼 -
library(dplyr)
data(iris)
filter(iris, grepl("nica",Species))
編輯:另一種選擇 - 在data.table()
功能%like%
library(dplyr)
data(iris)
##
Iris <- iris[
rep(seq_len(nrow(iris)),each=5000),
]
dim(Iris)
[1] 750000 5
##
library(microbenchmark)
library(data.table)
##
Dt <- data.table(Iris)
setkeyv(Dt,cols="Species")
##
foo <- function(){
subI <- filter(Iris, grepl("nica",Species))
}
##
foo2 <- function(){
subI <- Dt[Species %like% "nica"]
}
##
foo3 <- function(){
subI <- filter(Iris, Species %like% "nica")
}
Res <- microbenchmark(
foo(),foo2(),foo3(),
times=100L)
##
> Res
Unit: milliseconds
expr min lq median uq max neval
foo() 114.31080 122.12303 131.15523 136.33254 214.0405 100
foo2() 23.00508 30.33685 39.77843 41.49121 129.9125 100
foo3() 18.84933 22.47958 29.39228 35.96649 114.4389 100
'dplyr是唯一可以處理我843k data.frame'的軟件包 - 我強烈建議R package'數據。 table'。 – nrussell
我做出了關注dplyr語法和「跳過data.table」的決定。我的整個應用程序已提交給dplyr,因此data.table解決方案可以,但本機dplyr是最好的。我認爲dplyr是在引擎蓋下使用data.table。 – userJT
'dplyr'可以與數據表一起工作,但除非您明確加載'data.table'並將data.frames轉換爲data.tables,否則它不會在底層使用它。這樣做可能會增加額外的速度。 – Gregor