我有一个像:chr "ABC" "ABM" "AG" "AGB" "AGP" "AD".
这样的单词数据框
我想把它转换成列表(单词)的列表(字典),除以长度:
:chr NULL
:chr [1:2] "AD" "AG"
:chr [1:4] "ABC" "ABM" "AGB" "AGP"
答案 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")