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

问题描述 投票:1回答:1

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

:chr NULL
:chr [1:2] "AD" "AG"
:chr [1:4] "ABC" "ABM" "AGB" "AGP"
r list dictionary string-length
1个回答
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")
© www.soinside.com 2019 - 2024. All rights reserved.