0

Hei,

My aim is to do a histogramm.

Therefor I need unaggregated data - but unfortunately I only have it in aggregated form.

My data:

tribble(~date,~groupsize,
"2020-09-01",3,
"2020-09-02",2,
"2020-09-03",1,
"2020-09-04",2)

I want to have:

tribble(~date,~n,
        "2020-09-01",1,
        "2020-09-01",1,
        "2020-09-01",1,
        "2020-09-02",1,
        "2020-09-02",1,
        "2020-09-01",1,
        "2020-09-04",1,
        "2020-09-04",1)

I think this is really simple, but I am at a loss. Sorry for that!

What can I do? I really like dplyr solutions :-)

Thank you!

1 Answers1

0

repeat the date according to groupsize.

res <- data.frame(date=rep(dat$date, dat$groupsize), n=1)
res
#         date n
# 1 2020-09-01 1
# 2 2020-09-01 1
# 3 2020-09-01 1
# 4 2020-09-02 1
# 5 2020-09-02 1
# 6 2020-09-03 1
# 7 2020-09-04 1
# 8 2020-09-04 1
jay.sf
  • 60,139
  • 8
  • 53
  • 110