$中的错误:“关闭”类型的对象不可子集化

时间:2019-05-23 09:18:11

标签: r

此行中出现错误“警告:$中的错误:'closure'类型的对象不可子集” for(i in 1:nrow(mydata)){                 mydata $ Tags [i] = as.character(subset(train,train $ TagId == mydata $ MAXENTROPY_LABEL [i],“ Tag”)[1,])             }

observeEvent(input$getData, {
        output$data <- DT::renderDataTable({ 
            setwd("D:/New folder/New folder")
          load("maxent.rda")

new = read_csv("new.csv")
            new$Title = as.character(new$Title)
            new$Title = as.character(new$Title)
            new$Title[nrow(new)] = as.character(input$caption)
            new$Title = toupper(new$Title)
            new$Title = gsub("[<].*[>]", "", as.character(new$Title))
            new$Title = gsub("&amp", "", new$Title)
            new$Title = gsub("(RT|via)((?:\\b\\W*@\\w+)+)", "", new$Title)
            new$Title = gsub("@\\w+", "", new$Title)
            new$Title = gsub("[[:punct:]]", "", new$Title)
            new$Title = gsub("[[:digit:]]", "", new$Title)
            new$Title = gsub("http\\w+", "", new$Title)
            new$Title = gsub("[ \t]{2,}", "", new$Title)
            new$Title = gsub("^\\s+|\\s+$", "", new$Title)

matrix <- create_matrix(new["Title"], language="english", weighting=tm::weightTfIdf)
            container <- create_container(matrix, new$TagId, trainSize=NULL, testSize=1:nrow(new), virgin=TRUE)
            maxent_results <- classify_models(container,maxent_model)
            write.csv(maxent_results, "maxent_results.csv", row.names = FALSE)
            mydata = data.frame(new,maxent_results)
            mydata = mydata[nrow(mydata),]
            mydata = mydata[,c("Title","MAXENTROPY_LABEL", "MAXENTROPY_PROB")]
            mydata$Tags = rep("tag", nrow(mydata))
            for(i in 1:nrow(mydata)){
                mydata$Tags[i] = as.character(subset(train, train$TagId == mydata$MAXENTROPY_LABEL[i],"Tag")[1,])
            }
            mydata

0 个答案:

没有答案