我希望对一个字符向量进行排序,但是在排序中空格要排在连字符前面。
例如:
c("Want-#3","Want #2","I want to be first") %>% sort()
[1] "I want to be first" "Want-#3" "Want #2"
I would want it to have returned
[1] "I want to be first" "Want #2" "Want-#3"
显然,我可以使用sort中的"decreasing"选项,但是如果我想按升序排序,这种方法在包含其他非平凡元素的列表中就不适用了。
sessionInfo()
并展示结果吗?如果你正在使用UTF8,则空格应该出现在“-”之前。 - divibisan