开发者

Convert data format in R

I have a data set, dat, which was got from a model run.

The head of the dataset looks like this:

[[1]]

[1] -1

[[2]]

[2] -2

[[3]]

[3] -1

[[4]]

[4] 0

[[5]]

[5] -6

[[6]]

[6] -7

How can I convert dat to a simple data frame with a sing开发者_运维技巧le column like this

-1
-2
-1
0
-6
-7

Thanks

Dan


You have something like this:

L <- as.list(1:10)
L

So, one way is to:

> data.frame(name = t(data.frame(L)))
     name
X1L     1
X2L     2
X3L     3
X4L     4
X5L     5
X6L     6
X7L     7
X8L     8
X9L     9
X10L   10

Replace name with whatever you want the name of the variable to be.


You probably want to use the unlist function. For example:

unlist(list(1,2,3,4,5))
[1] 1 2 3 4 5

And you can turn it into a column by cbinding the results

a = unlist(list(1,2,3,4,5))
> cbind(a)
     a
[1,] 1
[2,] 2
[3,] 3
[4,] 4
[5,] 5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜