2016-06-28 70 views
1
a <- "dog cat carrot cabbage" 
b <- "orange cat chair cabbage" 
c <- "dog phone book beach" 
x <- data.frame(a,b,c) 
> x 
         a      b     c 
1 dog cat carrot cabbage orange cat chair cabbage dog phone book beach 

因此,这是建立在列。我想要的是一个1列数据框,每个字符串作为一行。我会怎么做?如何构建明智的数据框架而不是明智的列?

回答

5
d <- c(a,b,c) 
data.frame(d) 

输出:

      d 
1 dog cat carrot cabbage 
2 orange cat chair cabbage 
3  dog phone book beach 
1

另一种选择是使用as.data.frame

as.data.frame(c(a,b,c)) 

#  c(a, b, c) 
#1 dog cat carrot cabbage 
#2 orange cat chair cabbage 
#3 dog phone book beach 

您还可以使用rbind

rbind(a, b, c) 

# [,1]      
#a "dog cat carrot cabbage" 
#b "orange cat chair cabbage" 
#c "dog phone book beach" 
0

您可以通过建行矩阵,并且将其转换成一个DF可以得到所需的输出

data.frame(matrix(c(1, 7, 4, 6, 2, 0, 6, 2, 8), 3, 3, byrow = TRUE)) 
+0

此代码会产生错误。 – Megatron

+0

修复了代码。 – mkearney

0

使用rbind和as.data.frame功能。

as.data.frame(rbind(a,b,c))