我有一个非常大(在Excel中打开太大)生物数据集,看起来像这样
year <- c(1990, 1980, 1985, 1980, 1990, 1990, 1980, 1985, 1985,1990,
1980, 1985, 1980, 1990, 1990, 1980, 1985, 1985,
1990, 1980, 1985, 1980, 1990, 1990, 1980, 1985, 1985)
species <- c('A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'A','A', 'A',
'B', 'B', 'B', 'C', 'C', 'C', 'A', 'A', 'A', 'B', 'B', 'B',
'C', 'C', 'C', 'A')
region <- c(1, 1, 1, 3, 2, 3, 3, 2, 1, 1, 3, 3, 3, 2, 2, 1, 1, 1,1, 3, 3,
3, …
Run Code Online (Sandbox Code Playgroud) 我有一个有点复杂的数据结构(嵌套列表)y
,定义为:
x <- list(
list(1, "a", 2, "b", 0.1),
list(3, "c", 4, "d", 0.2),
list(5, "e", 6, "f", 0.3)
)
y <- rep(list(x), 10)
Run Code Online (Sandbox Code Playgroud)
我还有一个数据框df
,定义为:
df <- data.frame(
x1 = c( 0.33, 1.67, -0.62, -0.56, 0.17, 0.73, 0.59, 0.56, -0.22, 1.49),
x2 = c(-0.82, 1.22, 0.65, 0.54, -2.26, 1.21, -0.44, -0.92, -0.56, 0.50),
x3 = c(-0.16, 0.49, -0.82, -0.71, 0.13, 1.22, 1.23, -0.01, -1.11, 0.97)
)
Run Code Online (Sandbox Code Playgroud)
其中列名并不重要。
我想将所有和替换y[[i]][[j]][[5]]
为。我的 Python/Julia 大脑在循环中工作得最好,因此我通过循环,然后循环 的元素(每个 的副本)来完成此操作,如下所示:df[[i, j]] …
试图想出一种快速方法来确保 a 在 Julia 中是单调的。
\n我一直在使用的缓慢(且明显)的方法是这样的:
\nfunction check_monotonicity(\n timeseries::Array,\n column::Int\n)\n current = timeseries[1,column]\n for row in 1:size(timeseries, 1)\n if timeseries[row,column] > current \n return false\n end \n current = copy(timeseries[row,column])\n end \n return true\nend\n
Run Code Online (Sandbox Code Playgroud)\n所以它的工作原理是这样的:
\njulia> using Distributions\n\njulia>mono_matrix = hcat(collect(0:0.1:10), rand(Uniform(0.4,0.6),101),reverse(collect(0.0:0.1:10.0)))\n101\xc3\x973 Matrix{Float64}:\n 0.0 0.574138 10.0\n 0.1 0.490671 9.9\n 0.2 0.457519 9.8\n 0.3 0.567687 9.7\n \xe2\x8b\xae \n 9.8 0.513691 0.2\n 9.9 0.589585 0.1\n 10.0 0.405018 0.0\njulia> check_monotonicity(mono_matrix, 2)\nfalse\n
Run Code Online (Sandbox Code Playgroud)\n然后对于相反的例子:
\njulia> check_monotonicity(mono_matrix, 3)\ntrue\n
Run Code Online (Sandbox Code Playgroud)\n有谁知道对于长时间序列来说更有效的方法?
\n