Transform count column into number of rows [duplicate]
Using tidyr::uncount
you could do:
library(tidyr)
library(dplyr)
uncount(df1, nbird) %>%
mutate(nbird = 1)
#> lat lon nbird
#> 1 35 -96 1
#> 2 35 -96 1
#> 3 40 -101 1
#> 4 40 -101 1
#> 5 40 -101 1
#> 6 40 -101 1
#> 7 42 -97 1
#> 8 42 -97 1
With base R:
df2 <- df1[rep(1:nrow(df1), times = df1$nbird), ]
df2$nbird <- 1L
df2
#> lat lon nbird
#> 1 35 -96 1
#> 1.1 35 -96 1
#> 2 40 -101 1
#> 2.1 40 -101 1
#> 2.2 40 -101 1
#> 2.3 40 -101 1
#> 3 42 -97 1
#> 3.1 42 -97 1