如果我将输出指定为html_notebook(我的首选方法),我发现某些功能的运行速度会非常慢,但是如果将输出指定为html_document,则不会发现任何问题。
以下是示例代码中执行CrossTable函数(descr包)的报告时间:
有什么想法会导致我使用笔记本电脑时性能下降?
set.seed(7)
num.records <- 1000
df <- data.frame(var.a = sample(c('A', 'B', 'C'), num.records, replace = TRUE),
var.b = sample(c('X', 'Y', 'Z'), num.records, replace = TRUE))
str(df)
'data.frame': 1000 obs. of 2 variables:
$ var.a: chr "B" "C" "C" "C" ...
$ var.b: chr "X" "Y" "Z" "X" ...
start.time <- Sys.time()
with(df, descr::CrossTable(var.a, var.b, prop.chisq = F, format = 'SPSS'))
end.time <- Sys.time()
end.time - start.time
Cell Contents
|-------------------------|
| Count |
| Row Percent |
| Column Percent |
| Total Percent |
|-------------------------|
======================================
var.b
var.a X Y Z Total
--------------------------------------
A 105 118 120 343
30.6% 34.4% 35.0% 34.3%
31.8% 35.5% 35.5%
10.5% 11.8% 12.0%
--------------------------------------
B 117 116 111 344
34.0% 33.7% 32.3% 34.4%
35.5% 34.9% 32.8%
11.7% 11.6% 11.1%
--------------------------------------
C 108 98 107 313
34.5% 31.3% 34.2% 31.3%
32.7% 29.5% 31.7%
10.8% 9.8% 10.7%
--------------------------------------
Total 330 332 338 1000
33.0% 33.2% 33.8%
======================================
Time difference of 1.236148 mins