Skip to content

Converting a pdataframe into dataframe

3 messages · Apoorva Gupta, Peter Ehlers

#
Now, I want to convert b into a data frame and have a structure
similar to a. How do I do that?
#
On 2012-06-01 07:09, Apoorva Gupta wrote:
I assume that pdata.frame() is the function in package plm.
(You should say so.)

The solution depends a bit on just how similar your new data
frame should be to a.

If you don't mind the attributes attached to each variable in b,
then do just

   new.b <- as.data.frame(b)

which will invoke the as.data.frame.pdata.frame() function.

If you want to strip the attributes, then this should do:

   new.b <- lapply(b, function(x){attr(x, "index") <- NULL; x})

In either case, 'year' will still be a factor and you may
still wish to 'unfactor' it; see ?factor.

Peter Ehlers
--
#
Whoops, forgot one line of code; below.
On 2012-06-01 09:37, Peter Ehlers wrote:
This produces a list; we still need

     new.be <- data.frame(new.b)

Peter