R2-36第二阶段第三次作业

范志敏 2018-04-01 19:21:50 阅读: 399

installed.packages("killDbConnections")

library(RMySQL)

killDbConnections<-function(){

  all_cons<-dbListConnections(MySQL())

  print(all_cons)

  for(con in all_cons)

    +  dbDisconnect(con)

  print(paste(length(all_cons),"connections killed."))

}

killDbConnections()

con<-dbConnect(MySQL(),host="localhost",dbname="rdb",user="root",password="")

dbSendQuery(con,'SET NAMES utf8')

rs <- dbSendQuery(con,"SELECT * FROM article WHERE isdone=1")

words=data.frame(word=c(),freq=c())

while(!dbHasCompleted(rs)){

  chunk<-dbFetch(rs,10)

count=nrow(chunk)

  cnt=1

  while(cnt<=count){

    str=gsub("[[:punct:]]","", tolower(chunk[cnt,5]))

    temp=as.vector(unlist(strsplit(str,split=" ")))

    temp_len=length(temp)

    cnt2=1

    while(cnt2<=temp_len){

      if(temp[cnt2] %in% words$word){

        words[words$word==temp[cnt2],]$freq=words[words$word==temp[cnt2],]$freq+1

      }

      else{

        words=rbind(words,data.frame(word=c(temp[cnt2]),freq=c(1)))

      }

      cnt2=cnt2+1

    }

    cnt=cnt+1

  }

}

head(words)

第二题 install.packages("wordcloud2")始终安装不了

 
请登录后再评论
| 注册
{{item.nickname}} {{item.create_time}} {{item.floor}}楼
{{item.re_nickname}} 写于 {{item.re_time}}
切换到完整回复
科研狗 2015-2020 京ICP备16006621 科研好助手,专业的科研社交共享平台