0

I have a data table dt with 3 columns like this:

   coord_e coord_n proj_apartments
1: 2670789 1252252             120
2: 2670861 1252186              45
3: 2671109 1233883              34
4: 2671128 1244620              11
5: 2671134 1242050              39
6: 2671314 1241298              20

I want to repeat each row as many times as the number in the proj_apartmentscolumn – meaning the first row should be repeated 120 times, the second 45 and so long.

I think I need the rep() function, but I am struggling:

dt <- as.data.table(read.table(text = 
"coord_e coord_n proj_apartments
2670789 1252252             120
2670861 1252186              45
2671109 1233883              34
2671128 1244620              11
2671134 1242050              39
2671314 1241298              20", header=TRUE))

rep(dt[,c(coord_e,coord_n,proj_apartments)], times = dt[,proj_apartments])

The times argument is invalid in this way...

Can anyone help me here?

Mario
  • 2,393
  • 2
  • 17
  • 37

0 Answers0