gpt4 book ai didi

r - 计算 R 中拼错的单词

转载 作者:行者123 更新时间:2023-12-01 19:35:03 25 4
gpt4 key购买 nike

Row<-c(1,2,3,4,5)
Content<-c("I love cheese", "whre is the fish", "Final Countdow", "show me your s", "where is what")
Data<-cbind(Row, Content)
View(Data)

我想创建一个函数来告诉我每行有多少错误的单词。

中间步骤是让它看起来像这样:
Row<-c(1,2,3,4,5)
Content<-c("I love cheese", "whre is the fs", "Final Countdow", "show me your s", "where is what")
MisspelledWords<-c(NA, "whre, fs", "Countdow","s",NA)
Data<-cbind(Row, Content,MisspelledWords)

我知道我必须使用 aspell,但我在仅对行执行 aspell 时遇到问题,而不总是直接在整个文件上执行,最后我想计算每行有多少错误的单词为此,我将采用以下代码: Count the number of words in a string in R?

最佳答案

灵感来自 this article ,这是一个尝试 which_misspelledcheck_spellinglibrary(qdap) .

library(qdap)

# which_misspelled
n_misspelled <- sapply(Content, function(x){
length(which_misspelled(x, suggest = FALSE))
})

data.frame(Content, n_misspelled, row.names = NULL)
# Content n_misspelled
# 1 I love cheese 0
# 2 whre is the fs 2
# 3 Final Countdow 1
# 4 show me your s 0
# 5 where is what 0


# check_spelling
df <- check_spelling(Content, n.suggest = 0)

n_misspelled <- as.vector(table(factor(df$row, levels = Row)))

data.frame(Content, n_misspelled)
# Content n_misspelled
# 1 I love cheese 0
# 2 whre is the fs 2
# 3 Final Countdow 1
# 4 show me your s 0
# 5 where is what 0

关于r - 计算 R 中拼错的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25873444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com