由他们的长度分隔的词的字典

时间:2016-09-23 14:34:16

标签: r list dictionary string-length

我有一个像:chr "ABC" "ABM" "AG" "AGB" "AGP" "AD".这样的单词数据框 我想把它转换成列表(单词)的列表(字典),除以长度:

:chr NULL
:chr [1:2] "AD" "AG"
:chr [1:4] "ABC" "ABM" "AGB" "AGP"

1 个答案:

答案 0 :(得分:2)

您可以使用split

split(words, nchar(words))  # split the words vector by the number of characters
# $`2`
# [1] "AG" "AD"

# $`3`
# [1] "ABC" "ABM" "AGB" "AGP"

数据

words <- c("ABC", "ABM", "AG", "AGB", "AGP", "AD")