的R - 错误写入CSV
我有以下数据集时:的R - 错误写入CSV
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
了一些研究之后,我发现,这是因为我的数据集包含嵌套数据框,但建议的解决方案Like This没有帮助。 (在这种情况下,我得到了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)
以上是 的R - 错误写入CSV 的全部内容, 来源链接: utcz.com/qa/266169.html