r - 将不同长度的字符串列表组合到一个数据框中
问题描述
我有一个需要纠正英语错误的文本数据。
我想要一个表格的输出,第一列是错误,第二列是所有更正的建议。
例如:
sentence <- "This is a word but thhis isn't and this onne as well. I need hellp"
library(hunspell)
mistakesList <- hunspell(essay)[[1]]
suggestionsList <- hunspell_suggest(mistakesList)
我试过了
do.call(rbind, Map(data.frame, A=mistakesList, B=suggestionsList))
但它返回
A B
thhis thhis this
onne.1 onne none
onne.2 onne one
onne.3 onne tonne
onne.4 onne Donne
onne.5 onne once
onne.6 onne Anne
onne.7 onne Yvonne
hellp.1 hellp hello
hellp.2 hellp hell
hellp.3 hellp help
hellp.4 hellp hell p
我想要一个返回的数据框:
mistakes suggestions
thhis this
onne none one tonne Donne once Anne Yvonne
hellp hello hell help hell p
解决方案
我们可以保持mistakesList
原样并suggestionsList
使用toString
.
data.frame(mistakes = mistakesList, suggestions = sapply(suggestionsList, toString))
# mistakes suggestions
#1 thhis this
#2 onne none, one, tonne, Donne, once, Anne, neon
#3 hellp hello, hell, help, hell p
推荐阅读
- scala - Scala程序运行很慢
- python - 哪种python数据结构最适合我的用例动态增长?
- php - 如何在 Timber WordPress 插件中为 TWIG 添加沙盒扩展?
- java - modulate = 'true' 在 Log4j TimeBased Triggering Policy 中意味着什么
- javascript - Javascript 在会话中仅显示一次预加载器
- string - 在字符串中交换字符的最低成本,因此没有 3 个相同的字符是连续的
- java - 如何在@Pattern 中使用@Value
- python - (反向)按列对 2d numpy 数组进行排序
- angular - 过滤 Firebase 中的特定记录
- c++ - 未找到 WebKitWebFrame