连接R中的X行数
我有不同行数和列数的tibble;并且希望使用tidyverse将每一行连接到一个长行。请参见下面的示例数据连接R中的X行数,r,tidyverse,R,Tidyverse,我有不同行数和列数的tibble;并且希望使用tidyverse将每一行连接到一个长行。请参见下面的示例数据 #Example data 1: x <- as_tibble(matrix(1:9, ncol=3)) #wanted: x = c(1,4, 2, 5, 8, 3, 6, 9) #Example data 2: x <- as_tibble(matrix(1:10, ncol=2)) #wanted: x = c(1, 6, 2, 7, 3, 8, 4
#Example data 1:
x <- as_tibble(matrix(1:9, ncol=3))
#wanted:
x = c(1,4, 2, 5, 8, 3, 6, 9)
#Example data 2:
x <- as_tibble(matrix(1:10, ncol=2))
#wanted:
x = c(1, 6, 2, 7, 3, 8, 4, 9, 5, 10)
提前谢谢。我们可以转置和连接
c(t(x))
我们可以转置和连接
c(t(x))
我认为@akrun的解决方案是最简单的。这里有一个更复杂的解决方法:P
> unlist(split(x,1:nrow(x)),use.names = FALSE)
[1] 1 4 7 2 5 8 3 6 9
我认为@akrun的解决方案是最简单的。这里有一个更复杂的解决方法:P
> unlist(split(x,1:nrow(x)),use.names = FALSE)
[1] 1 4 7 2 5 8 3 6 9