对于imputeTS包,我在将数组中的NA传递给R时遇到了一些问题。
假设我有这样的数组:
a = Any[1, 2, 3, NaN, 5]我想把它传递给这个:
R"""
b <- na_seadec($a, algorithm = "kalman", find_frequency = TRUE, maxgap = Inf)
"""NaN不会自动转换为NA。如何才能将NA值准确地传递给RCall?
发布于 2020-04-26 04:23:21
Julia中的NaN将是R中的NaN。如果你想在R中使用NA,则应该在Julia中使用missing:
julia> x = [1, 2, NaN]
3-element Array{Float64,1}:
1.0
2.0
NaN
julia> y = [1, 2, missing]
3-element Array{Union{Missing, Int64},1}:
1
2
missing
julia> R"$x"
RObject{RealSxp}
[1] 1 2 NaN
julia> R"$y"
RObject{IntSxp}
[1] 1 2 NA您可以在Julia手册的this section中找到详细信息。
下面是一个示例会话:
julia> R"library(imputeTS)"
RObject{StrSxp}
[1] "imputeTS" "stats" "graphics" "grDevices" "utils" "datasets"
[7] "methods" "base"
julia> a = [1,2,3,missing,5]
5-element Array{Union{Missing, Int64},1}:
1
2
3
missing
5
julia> R"""
b <- na_seadec($a, algorithm = "kalman", find_frequency = TRUE, maxgap = Inf)
"""
┌ Warning: RCall.jl: Warning in na_seadec(`#JL`$a, algorithm = "kalman", find_frequency = TRUE, :
│ No seasonality information for dataset could be found, going on without decomposition.
│ Setting find_frequency=TRUE might be an option.
└ @ RCall ~/.julia/packages/RCall/g7dhB/src/io.jl:113
RObject{RealSxp}
[1] 1 2 3 4 5https://stackoverflow.com/questions/61431585
复制相似问题