Message-ID: <4FC8EFCF.7050604@ucalgary.ca>
Date: 2012-06-01T16:37:35Z
From: Peter Ehlers
Subject: Converting a pdataframe into dataframe
In-Reply-To: <CAMGeiAt7NikGNY0FETybgQ5-aF3Ub40Z3j_ahGfy_t6nfvFA_A@mail.gmail.com>
On 2012-06-01 07:09, Apoorva Gupta wrote:
>> a<- data.frame(name=c(rep("a",5), rep("b",5)), year=c(1989:1993, 1989:1993), var=c(1:10))
>> str(a)
>> b<- pdata.frame(a, index=c("name","year"))
>> str(b)
> Now, I want to convert b into a data frame and have a structure
> similar to a. How do I do that?
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
--