我有一个想要重新排序的矩阵,这样行就以指定行尾的字符开始(在我的示例中是"~~"
).解释我想要什么的最简单的方法是,我希望我的矩阵右对齐,而不是左对齐.
我想不出一种简单的方法来做这件事,但我认为肯定有这种方法.
input = structure(list(V1 = c("Home", "Home", "Home", "Home", "Home"),
V2 = c("Asia", "Europe", "Americas", "Europe", "Asia"), V3 = c("Japan",
"Germany", "Washington", "France", "~~"), V4 = c("Tokyo",
"NRW", "~~", "Paris", "~~"), V5 = c("~~", "Dusseldorf", "~~",
"~~", "~~"), V6 = c("~~", "~~", "~~", "~~", "~~")),
class = "data.frame", row.names = c(NA, -5L))
这是我想要的输出:
output = structure(list(V1 = c("~~", "~~", "~~", "~~", "~~"), V2 = c("~~",
"Home", "~~", "~~", "~~"), V3 = c("Home", "Europe", "~~", "Home",
"~~"), V4 = c("Asia", "Germany", "Home", "Europe", "~~"), V5 = c("Japan",
"NRW", "Americas", "France", "Home"), V6 = c("Tokyo", "Dusseldorf",
"Washington", "Paris", "Asia")),
class = "data.frame", row.names = c(NA, -5L))