小编Joj*_*ack的帖子

R:化学计算微分方程中的时间相关参数(工作)

编辑:公式中有错误,现在一切都按预期进行。感谢让我审查代码的建议

我正在尝试研究一个非常著名的化学方程式 Šesták–Berggren,它代表了一个强大的工具,用于通过模型拟合方法描述动力学数据,取自 DOI:10.1016/j.tca.2011.03.030。没有可用于模拟它的免费/开放包,所以我试图将它添加到我自己的动态包 takos https://cran.r-project.org/web/packages/takos/index.html。由于它是逻辑函数的“变体”,我正在考虑使用 deSolve 包。唯一的问题是我有一个依赖于时间的参数。我认为它可以使用 approx fun 解决,但我被困在那里的代码 [现在工作]

 rm(list=ls())
library(deSolve)
A=10^6.3 #parameter needed by the function which is "fixed"
Ea=80000 #an example of activation energy
R=8.314  #gas constant
npoints=100 #just 1000 points to start
qqq=5  #ratio
T0=0   #starting temperature
T.end=1200 #end temperature
Ts=273.15+T0 #transformation in K
time.e=(T.end-T0)/(qqq/60) #estimated time for the analysis
time.s=seq(0.1,time.e, length.out=npoints) #vector with all the times
Temp=Ts+(time.s*(qqq/60)) #temperatures calculated at each time
tm=time.s
m=1 #parameter in the Sestak-Berggen Equation da/dt=A*exp(-Ea/RT)*a^m*(1-a)^n
n=2#secon parameter …
Run Code Online (Sandbox Code Playgroud)

r chemistry logistics differential-equations

5
推荐指数
0
解决办法
74
查看次数

R data.table .SD 意外行为

我试图计算数据表的一些基本统计数据,但我遇到了这种(对我而言)意外的行为。如果我使用“显式”索引使用所有内容进行计算,则一切都按预期工作,如下例所示:

library(data.table)
n <- 100; reps <- 6; n1 <- 2
df <-  as.data.frame(cbind(matrix(seq_len(n*n1), ncol=n1),
      matrix(sample(0:1000, n*reps, replace=TRUE), ncol=reps)))
dt <- data.table(df)

dtmean <- dt[, lapply(.SD[,c(seq(2,5))], mean, na.rm=TRUE), by=c("V1")]
Run Code Online (Sandbox Code Playgroud)

但如果我使用

a=2
b=5

dtmean <- dt[, lapply(.SD[,c(seq(a,b))], mean, na.rm=TRUE), by=c("V1")]
Run Code Online (Sandbox Code Playgroud)

结果不是我所期望的(前几行)

这是故意的 data.table 应该如何工作吗?

所以 n=10 的第一部分代码给出

   V1  V3  V4  V5  V6
 1:  1 504 399 430 564
 2:  2 547 294 274 700
 3:  3 555 305 781 326
 4:  4 144 840 983 221
 5:  5 894 659 169 …
Run Code Online (Sandbox Code Playgroud)

r data.table

1
推荐指数
1
解决办法
38
查看次数