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 single column like this

-1
-2
-1
0
-6
-7

Thanks

Dan

Answers


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

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.


Need Your Help

Selecting multiple cells in Silverlight 4 Datagrid

.net silverlight-4.0 datagrid

I have some 6 columns in Silverlight 4 Datagrid. On each cell in the data grid, we have some custom controls got displayed. Now i should allow the user to select one control from each of the columns.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.