Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 RI 中有这样的字符串:
'hello'
如何将其转换为这样的字符向量:
[1] "h" "e" "l" "l" "o"
与stringr:
stringr
stringr::str_split("hello","")[[1]] [1] "h" "e" "l" "l" "o"
找到了另一种可能的解决方案,尽管这可能是最糟糕的方法:
substring("hello", seq(1,nchar("hello")), seq(1,nchar("hello"))) [1] "h" "e" "l" "l" "o"
虽然这可能不是最高效的解决方案,但它可以按预期工作:
> unlist(strsplit('hello', '')) [1] "h" "e" "l" "l" "o"
有关更多选项,请参阅unlist和strsplit的文档。