"R TermDocumentMatrix 단어 이름변경"의 두 판 사이의 차이

3번째 줄: 3번째 줄:


<source lang='r'>
<source lang='r'>
library(tm) # TermDocumentMatrix()
zTdmRenameTerm <- function(tdm, term1, term2) {
zTdmRenameTerm <- function(tdm, term1, term2) {
   nms <- rownames(tdm)
   nms <- rownames(tdm)

2019년 12월 14일 (토) 14:58 판

1 개요

R TermDocumentMatrix 용어 이름변경
library(tm) # TermDocumentMatrix()

zTdmRenameTerm <- function(tdm, term1, term2) {
  nms <- rownames(tdm)
  nms[which(nms==term1)] <- term2
  rownames(tdm) <- nms
  return(tdm)
}

docs1 <- c("안녕, 안녕.", "반갑다, 친구들.", "반갑다, 친구야, 친구야")
docs1 <- iconv(docs1, "CP949", "UTF-8")
tdm1 <- TermDocumentMatrix(Corpus(VectorSource(docs1)),control=list(removePunctuation=T,stopwords=F))
inspect(tdm1)
## <<TermDocumentMatrix (terms: 4, documents: 3)>>
## Non-/sparse entries: 5/7
## Sparsity           : 58%
## Maximal term length: 3
## Weighting          : term frequency (tf)
## Sample             :
##   
##         Docs
## Terms    1 2 3
##   반갑다 0 1 1
##   안녕   2 0 0
##   친구들 0 1 0
##   친구야 0 0 2

tdm2 <- zTdmRenameTerm(tdm1, "친구들", "친구")
inspect(tdm2)
## Non-/sparse entries: 5/7
## Sparsity           : 58%
## Maximal term length: 3
## Weighting          : term frequency (tf)
## Sample             :
##         Docs
## Terms    1 2 3
##   반갑다 0 1 1
##   안녕   2 0 0
##   친구   0 1 0
##   친구야 0 0 2

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}