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