Julia 中是否有类似于 R 负索引的功能?在 R 中,代码类似于:
x = 1:10
inds = c(1, 5, 7)
x[-inds]
[1] 2 3 4 6 8 9 10
Run Code Online (Sandbox Code Playgroud)
我发现这在许多情况下都非常有用,特别是对于采样索引以创建测试/训练集之类的事情,而且还可以对数组进行子索引以排除某些行。所以我希望 Julia 中有一些简单的东西可以做到同样的事情。
我似乎无法在Julia版本0.6.4中将值更改为缺失(我相信它在0.6之前被允许).
示例代码:
using Dataframes
x = zeros(5)
5-element Array{Float64,1}:
0.0
0.0
0.0
0.0
0.0
x[3] = missing
ERROR: MethodError: Cannot `convert` an object of type Missings.Missing to an
object of type Float64
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] setindex!(::Array{Float64,1}, ::Missings.Missing, ::Int64) at ./array.jl:583
Run Code Online (Sandbox Code Playgroud)
在此设置中,我尝试将某些指标编码为分析的缺失值.有一个简单的解决方法吗?