0

I have a dataset that I exported from SQL that has the following format:

> head(my_data)
# A tibble: 6 x 19
  referencedate       var1             var2  cases var3       var4 var5
  <dttm>                  <dbl>        <dbl> <dbl> <chr>          <dbl>         <dbl>
1 2008-03-31 00:00:00         1            1     1 255124~           -1            -1
2 2008-03-31 00:00:00         1            1     3 441344~           -1            -1
3 2008-03-31 00:00:00         1            1     5 133497~            1             0
4 2008-03-31 00:00:00         1            1     7 343242~            1            -1
5 2008-03-31 00:00:00         1            1     100 292297~            1            -1
6 2008-03-31 00:00:00         1            1     1 159941~           -1             0

If I run a logistic regression, the software thinks that each row is one observation, while depending on the value of cases there are multiple observations with the same values. How can I incorporate this in my analysis? This could be done by either generating multiple rows for when cases > 1, or with some other way...?

adrCoder
  • 3,145
  • 4
  • 31
  • 56
  • Yes, R assume every row is an independent observation. Can you describe what is the response variable (Y) ? Also seems the reference date is the same in all rows. – Areza Nov 08 '19 at 11:03
  • The response variable is 0 or 1. I just want to duplicate the rows for which cases > 1. This is just the head of my dataset, referencedate is different in other rows. – adrCoder Nov 08 '19 at 11:05
  • 1
    If you want to expand your data by duplicating the rows that have `cases > 1`, a possibility would be: `my_data2 <- my_data[rep(seq(nrow(my_data)), my_data$cases), ]` – Jaap Nov 08 '19 at 11:06
  • as @jaap said, https://stackoverflow.com/questions/11121385/repeat-rows-of-a-data-frame – Areza Nov 08 '19 at 11:10
  • @Jaap post your answer and I will accept it. – adrCoder Nov 08 '19 at 11:14
  • @adrCoder this has been answered before; see the link inlcuded at the top of the question now – Jaap Nov 08 '19 at 11:50

0 Answers0