【问题标题】:parsing input variabele to dataframe filter results in undefined columns selected将输入变量解析为数据框过滤器会导致选择未定义的列
【发布时间】:2023-04-06 07:31:01
【问题描述】:

我使用了一个基于以下语句返回 data.frame 的函数(工作正常!)

group <- data.frame(getGroupedData(getTweetTraining(openDBSentiment()))[getGroupedData(getTweetTraining(openDBSentiment()))$Group.2 ==  "test"])

我想使用的参数(输入)将其传递给数据框的过滤器会导致错误(选择未定义的列)作为结果。

getBarFrame <- function (input) {
 #Build dataframe from other functions
  group  <-  data.frame(getGroupedData(getTweetTraining(openDBSentiment())))
  #Filter the data.frame based on the input parameter
  group2 <-  group[group$Group.2 ==  input ]
  #select only 2 fields of the data.frame
  group3 <- group2[c("Group.1","sentiment")]
  #return the result tot the function
return (group3)
}

你知道如何解决这个问题

【问题讨论】:

  • 把它变成多行,将中间结果保存到不同的变量中,你就会很好地了解实际发生了什么以及问题发生在哪一步。
  • 谢谢,劳里克。它可以解决这个特殊的问题。

标签: r function


【解决方案1】:

该问题的解决方案是您必须将 lower , after 过滤data.frame。

getBarFrame <- function (input) {
 #Build dataframe from other functions
  group  <-  data.frame(getGroupedData(getTweetTraining(openDBSentiment())))
  #Filter the data.frame based on the input parameter
  group2 <-  group[group$Group.2 ==  input , ]
  #select only 2 fields of the data.frame
  group3 <- group2[c("Group.1","sentiment")]
  #return the result tot the function
return (group3)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-13
    • 2021-12-27
    • 2019-11-14
    • 2020-07-11
    • 2020-03-19
    • 2017-09-22
    • 2011-02-11
    • 2018-10-22
    相关资源
    最近更新 更多