http://tidytextmining.com/sentiment.html#the-sentiments-dataset을 기반으로 정서 분석을 시도하고 있습니다. 정서 분석을 수행하기 전에 데이터 세트를 깔끔한 형식으로 변환해야합니다.단어 개수로 데이터 프레임 변환하기
내 데이터 집합 형식이다 : 행 당 하나 명의 관찰로 변환하기 위해
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
url text
1 test1 this is test text1
2 test2 this is test text2
텍스트 열을 처리하고 해당 URL이 나타납니다 단어와 횟수를 포함 새 열을 추가해야합니다. 동일한 URL이 여러 행에 나타납니다.
# A tibble: 2 x 2
res.text n
<fctr> <int>
1 this is test text1 1
2 this is test text2 1
어떻게 고해상도 $ 텍스트 dataframe 단어를 계산하고 감정 분석을 수행하기 위해 URL을 유지하기 위해 : 리턴
library(tidyverse)
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
res_1 <- data.frame(res$text)
res_2 <- as_tibble(res_1)
res_2 %>% count(res.text, sort = TRUE)
: 여기
내 시도?업데이트 :
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
res %>%
group_by(url) %>%
transform(text = strsplit(text, " ", fixed = TRUE)) %>%
unnest() %>%
count(url, text)
반환 오류 : 당신이 http://tidytextmining.com/sentiment.html#the-sentiments-dataset
왜 변환해야합니까? 즉, 귀하의 제목이 실제 질문을 나타내는 것 같지 않습니다. 그것은 단어 하나당 url을 원한다고 생각합니다. %% unnest() %> % count (url, text);}}}} 가능한 한 티브 (tibbliverse) 접근법은'res %> % group_by (url) %> % transform (text = strsplit (text, "고정 = TRUE))'('text'는 문자열이고 인자가 아니라고 가정) –
@DavidArenburg 업데이트를 참조하십시오 –