0

I have a data set looking at 22.000 individuals. However there is a time variable to it telling me when this individual was observed the first time and when the last time. So I produced an additional column that tells me the absolute number of quarters that the individual was observed. Now I want to make this dataset a panel data set and replicate each individual by the number of quarter it has been observed. I found this question

Replicate each row of data.frame and specify the number of replications for each row

which matches my concern very well. but punching in the code:

df.expanded <- df[rep(seq(nrow(df)), df$Quartale), 1:2]

"Quartale" is name of the Var for quarters produces this error: Error in df$Quatarle : object of type 'closure' is not subsettable

Hack-R
  • 22,422
  • 14
  • 75
  • 131
FMin
  • 15
  • 4
  • 1
    Welcome to StackOverflow! For code debugging please always ask with a [reproducible](https://stackoverflow.com/q/5963269/1422451) example per the [MCVE](https://stackoverflow.com/help/mcve) and [`r`](https://stackoverflow.com/tags/r/info) tag description, with the desired output. You can use `dput()`, `reprex::reprex()` or built-in data sets for reproducible data. – Hack-R Jul 09 '18 at 15:30
  • Can you share what your dataframe looks like? And tell us the type of `df$Quartale` using `typeof()` – gos Jul 09 '18 at 15:43
  • Based on that error message, it also looks like you might have a typo. Is it `df$Quartale` or `df$Quatarle` – Dave Gruenewald Jul 09 '18 at 15:49
  • Sorry, for not getting back earlier...So I went back into the data and made several summary stats and in the end decided that the additional observation come with only very little variation, so I would artificially increase dataset. Hence, I did not follow up on this. again sorry for the late reply and thanks for the help! – FMin Jul 27 '18 at 10:14

1 Answers1

0

It is more difficult to assess this without an example dataset, but I think you can use the tidyr package for this.

Assuming your data df, and your frequency count is df$Quartale, then the following should work:

library(tidyr)
uncount(df, Quartale)
Dave Gruenewald
  • 5,329
  • 1
  • 23
  • 35