【问题标题】:R, Rexcel, create macro that counts of words in and excel worksheetR,Rexcel,创建计算字数的宏和 Excel 工作表
【发布时间】:2016-10-05 06:34:52
【问题描述】:

我使用 Rexcel 的以下宏不起作用。 我有一个 A1:A2 (mydf) 范围内的单词列表,我想计算一个特定单词 (hello) 的出现次数,但以下效果不佳。有人可以帮我理解吗?

Sub findwords()
Worksheets("Sheet1").Activate
rinterface.StartRServer
rinterface.PutDataframe "mydf", Range("Sheet1!A1:A200")
rinterface.RRun "a <- length(grep(hello, mydf))"
rinterface.PutArray "a", Range("Sheet1!B2:B50")

End Sub

【问题讨论】:

    标签: r macros word-count rexcel


    【解决方案1】:

    以下代码是正确答案:

    Sub findwords()
      MsgBox "finding the word hello"
      Rinterface.StartRServer
      Rinterface.PutArray "mydf", Range("Sheet1!A1:A200")
      Rinterface.RRun "a <- length(grep('hello', mydf))"
      Rinterface.GetArray "a", Range("Sheet1!B1")
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多