Skip to content
Prev 350540 / 398503 Next

Stacking of vectors to form a column vector

Hi,

Given that a data frame is a list:

  unlist(mydata[, 1:3])

For example:
[1] TRUE


Also, note that the returned result in both cases above retains names:
Sepal.Length1   Sepal.Length2   Sepal.Length3   Sepal.Length4 
            5.1             4.9             4.7             4.6 
  Sepal.Length5   Sepal.Length6   Sepal.Length7   Sepal.Length8 
            5.0             5.4             4.6             5.0 
  Sepal.Length9  Sepal.Length10  Sepal.Length11  Sepal.Length12 
            4.4             4.9             5.4             4.8 
...

You can just get the plain vector by using:
[1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7
 [17] 5.4 5.1 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4
 [33] 5.2 5.5 4.9 5.0 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6
 [49] 5.3 5.0 7.0 6.4 6.9 5.5 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1
...


As Bert notes, the indices would need to be adjusted for the actual data frame in question.

Regards,

Marc