gpt4 book ai didi

R-Excel VBA : how to extract values returned by GetArrayToVBA?

转载 作者:行者123 更新时间:2023-12-04 20:20:23 25 4
gpt4 key购买 nike

我正在尝试编写 R-Excel vba 插件,但无法使用 GetArrayToVBA .

例子:

RInterface.StartRServer
RInterface.RRun "mytst<-4"
Dim tstVar As Variant, tst As Double
tstVar = RInterface.GetArrayToVBA("mytst")
tst = CDbl(testVar)
MsgBox "count = " & CStr(tst)
RInterface.StopRServer

结果消息框显示 count = 0 .我期待 count = 4 .

最佳答案

这是一个 VBA 问题。您不能使用 CDbl() 将 1x1 数组类型转换为 double 来获取该数组中的值。您必须从数组中为其提供所需的索引 (0,0)。以下作品:

RInterface.StartRServer
RInterface.RRun "mytst<-as.matrix(4)"
Dim tstVar As Variant, tst As Double
tstVar = RInterface.GetArrayToVBA("mytst")
tst = CDbl(tstVar(0, 0))
MsgBox "count = " & CStr(tst)
RInterface.StopRServer

关于R-Excel VBA : how to extract values returned by GetArrayToVBA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5199206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com