【发布时间】:2018-02-26 13:32:34
【问题描述】:
使用这些数据:
library(tidyverse)
df <-
structure(
list(
start_depth = c(10, 15, 20, 25, 30),
end_depth = c(15,
20, 25, 30, 35),
k = c(
0.136,
0.135,
0.133,
0.139,
0.132
)
),
row.names = c(NA,-5L),
class = c("tbl_df", "tbl", "data.frame"),
.Names = c("start_depth",
"end_depth", "k")
)
df
#> # A tibble: 5 x 3
#> start_depth end_depth k
#> <dbl> <dbl> <dbl>
#> 1 10.0 15.0 0.136
#> 2 15.0 20.0 0.135
#> 3 20.0 25.0 0.133
#> 4 25.0 30.0 0.139
#> 5 30.0 35.0 0.132
我想使用以下等式为每对 end_depth 和 start_depth 传播一个值,增量为 1 米。
例如,假设我以 start_val = 0.001 开始 30-35 米课程:
end_depth = 35
0.001000000 = 0.001000000 * exp(0.132 * (35 - (35)))
end_depth = 34
0.001141108 = 0.001000000 * exp(0.132 * (35 - (34)))
end_depth = 33
0.001302128 = 0.001000000 * exp(0.132 * (35 - (33)))
end_depth = 32
0.001485869 = 0.001000000 * exp(0.132 * (35 - (32)))
end_depth = 31
0.001695538 = 0.001000000 * exp(0.132 * (35 - (31)))
end_depth = 30
0.001934792 = 0.001000000 * exp(0.132 * (35 - (30)))
然后,25-30 米类,我会重新开始,但使用最后计算的值(即 0.001934792)
end_depth = 30
0.001934792 * exp(0.139 * (30 - (30)))
end_depth = 29
0.001934792 * exp(0.139 * (30 - (29)))
我正在使用 dplyr,但任何其他选项都有效(例如:base R.data.table 等)
由reprex package (v0.2.0) 于 2018 年 2 月 26 日创建。
【问题讨论】: