다음 데이터 세트가 있습니다.
Artist Song.Rank Song.Title Word WordCount SentimentScore.text SentimentScore.sentiment
1 Placeholder 60 More Placeholders alright 40 alright Neutral
2 Placeholder 60 More Placeholders bad 79 bad Negative
3 Placeholder 60 More Placeholders bad 192 bad Negative
4 Placeholder 60 More Placeholders better 125 better Positive
5 Placeholder 60 More Placeholders brand 24 brand Neutral
6 Placeholder 60 More Placeholders break 106 break Negative
7 Placeholder 60 More Placeholders cause 18 cause Neutral
8 Placeholder 60 More Placeholders come 59 come Neutral
이 데이터 세트는 xlsx 파일의 데이터로 존재합니다. 마지막 열만 패키지 Sentiment
를 사용하여 직접 추가 한 것 RSentiment
입니다.
csv에 삽입하려고하면 다음 메시지가 표시됩니다.
> write.csv(dataset,"calculated.csv")
Error in if (inherits(X[[j]], "data.frame") && ncol(xj) > 1L) X[[j]] <- as.matrix(X[[j]]) :
missing value where TRUE/FALSE needed
약간의 조사 끝에 내 데이터 세트에 중첩 된 데이터 프레임이 포함되어 있기 때문에 이런 일이 발생한다는 것을 알게되었지만 이와 같은 제안 된 솔루션 이 도움 이 되지 않았습니다. (이 경우 invalid subscript type 'closure'
오류가 발생했습니다.)
편집하다 : 나는 이것이 묻는 많은 게시물을 보았다.
> str(dataset)
'data.frame': 28 obs. of 6 variables:
$ Artist : chr "Placeholder" "Placeholder" "Placeholder" "Placeholder" ...
$ Song.Rank : num 60 60 60 60 60 60 60 60 60 60 ...
$ Song.Title : chr "More Placeholder" "More Placeholder" "More Placeholder" "More Placeholder" ...
$ Word : chr "alright" "bad" "bad" "better" ...
$ WordCount : num 40 79 192 125 24 106 18 59 138 146 ...
$ SentimentScore:'data.frame': 28 obs. of 2 variables:
..$ text : Factor w/ 23 levels "alright","bad",..: 1 2 2 3 4 5 6 7 8 9 ...
..$ sentiment: Factor w/ 3 levels "Negative","Neutral",..: 2 1 1 3 2 1 2 2 2 2 ...
여기서 중첩 된 data.frames를 원하지 않는다고 가정합니다. 그런 다음 다음과 같이하십시오.
new_dataset <- data.frame(subset(dataset, select = -c(SentimentScore)),
dataset$SentimentScore)
write.csv(new_dataset,
file = "dataset.csv",
quote = FALSE)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다