【发布时间】:2017-05-19 12:50:11
【问题描述】:
我有以下数据框和 dplyr 方法来过滤和变异:
library(tidyverse)
infile <- "https://nopaste.me/view/raw/767f65cf" # this link will exist forever
gene_list <- c("ITGAM","ARG1")
dat <- read_delim(infile,delim=",", col_types = cols()) %>%
mutate(log_TPM = log(TPM)) %>%
filter(gene_symbol %in% gene_list)
dat
#> # A tibble: 236 × 5
#> gene_symbol sample_id TPM category log_TPM
#> <chr> <chr> <dbl> <chr> <dbl>
#> 1 ARG1 SPL_128 2.32 Medication- 0.8415672
#> 2 ITGAM SPL_128 14.92 Medication- 2.7027026
#> 3 ARG1 SPL_129 1.14 Medication- 0.1310283
#> 4 ITGAM SPL_129 17.49 Medication- 2.8616293
#> 5 ARG1 SPL_130 8.02 Medication- 2.0819384
#> 6 ITGAM SPL_130 3.65 Medication- 1.2947272
#> 7 ARG1 SPL_131 0.81 Medication- -0.2107210
#> 8 ITGAM SPL_131 1.81 Medication- 0.5933268
#> 9 ARG1 SPL_132 0.00 Medication- -Inf
#> 10 ITGAM SPL_132 1.41 Medication- 0.3435897
#> # ... with 226 more rows
实际上它包含大约 500 万行而不是 236 行。 使用 dplyr 非常慢。 data.table 的做法是什么?
【问题讨论】:
-
我想你想要的是
setDT(dat)[gene_symbol %in% gene_list, log_TPM := log(TPM)]
标签: r data.table