我创建了一个简单的例子来说明我目前遇到的问题.
我有一个名为example.Rmd的R-markdown文件,其中包含以下代码
```{r}
plot(rnorm(10000))
```
Run Code Online (Sandbox Code Playgroud)
和一个包含以下内容的Makefile文件
all : example01.html example02.html
example01.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example01.html')"
example02.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example02.html')"
Run Code Online (Sandbox Code Playgroud)
如果我按顺序运行Makefile文件
make
Run Code Online (Sandbox Code Playgroud)
没有问题.
如果我并行运行makefile
make -j 2
Run Code Online (Sandbox Code Playgroud)
knit2html函数生成的块重叠,两个html文件包含相同的图像.
有什么建议吗?我一直在寻找解决方案,但我一无所获.
我有以下函数来描述变量
library(dplyr)
describe = function(.data, variable){
args <- as.list(match.call())
evalue = eval(args$variable, .data)
summarise(.data,
'n'= length(evalue),
'mean' = mean(evalue),
'sd' = sd(evalue))
}
Run Code Online (Sandbox Code Playgroud)
我想用它dplyr来描述变量.
set.seed(1)
df = data.frame(
'g' = sample(1:3, 100, replace=T),
'x1' = rnorm(100),
'x2' = rnorm(100)
)
df %>% describe(x1)
# n mean sd
# 1 100 -0.01757949 0.9400179
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试应用相同的descrptive使用函数时group_by,描述函数不会应用于每个组
df %>% group_by(g) %>% describe(x1)
# # A tibble: 3 x 4
# g n mean sd
# <int> <int> <dbl> <dbl>
# …Run Code Online (Sandbox Code Playgroud) 有人对使用dplyr包的这种结果有解释吗?
我有一个 data.frame df
library(dplyr)
df = data_frame(
'id' = c(1,2,2,2,2,3,3,3,3),
'start' = c(881, 1611, 1611, 1642, 1764, 0, 0, 28, 59),
'end' = c(1089, 1819, 1819, 1850, 1972, 208, 208,236, 267))
Run Code Online (Sandbox Code Playgroud)
那看起来像
# Source: local data frame [9 x 3]
#
# id start end
# (dbl) (dbl) (dbl)
# 1 1 881 1089
# 2 2 1611 1819
# 3 2 1611 1819
# 4 2 1642 1850
# 5 2 1764 1972
# 6 3 …Run Code Online (Sandbox Code Playgroud) 我有一个组合样本,我想拟合Dirichlet分布的有限混合.更准确地说,请考虑以下示例:
library(gtools)
set.seed(1)
PROB = c(0.25, 0.15, 0.60)
ALPHA = list(
c(1,1,1),
c(2,1,1),
c(1,1,20)
)
size = 500
N = sapply(1:3, function(i, z) sum(z == i),
sample(1:3, size, prob = PROB, replace = TRUE))
X = do.call('rbind',
sapply(1:3, function(i, N)
rdirichlet(N[i], ALPHA[[i]]), N))[sample(1:size),]
Run Code Online (Sandbox Code Playgroud)
X包含由三部分单形中定义的Dirichlet分布混合生成的样本.该混合物的第一个Dirichlet分量具有参数(1,1,1),第二个分量具有参数(2,1,1)和第三个(1,1,20).混合概率为0.25,0.15,0.60.我想从样本中检索这些参数.
你怎么会找到这个参数?
r ×4
dplyr ×2
dirichlet ×1
distribution ×1
knitr ×1
lag ×1
makefile ×1
packages ×1
r-markdown ×1