Displaying 4 results from an estimated 4 matches for "d_df".
2017 Nov 29
0
dplyr - add/expand rows
...ata.table-based) solution.
Enjoy! ;)
Cheers,
Denes
--------------------------
## packages ##########################
library(dplyr)
library(data.table)
library(IRanges)
library(microbenchmark)
## prepare example dataset ###########
## use Bert's example, with 2000 stations instead of 2
d_df <- data.frame( station = rep(rep(c("one","two"),c(5,4)), 1000L),
from = as.integer(c(60,61,71,72,76,60,65,82,83)),
to = as.integer(c(60,70,71,76,83,64, 81, 82,83)),
record = c("A","B","C&q...
2017 Nov 29
2
dplyr - add/expand rows
...----------------
>
>
> ## packages ##########################
>
> library(dplyr)
> library(data.table)
> library(IRanges)
> library(microbenchmark)
>
> ## prepare example dataset ###########
>
> ## use Bert's example, with 2000 stations instead of 2
> d_df <- data.frame( station = rep(rep(c("one","two"),c(5,4)), 1000L),
> ??????????????????? from = as.integer(c(60,61,71,72,76,60,65,82,83)),
> ??????????????????? to = as.integer(c(60,70,71,76,83,64, 81, 82,83)),
> ??????????????????? record = c("A","B&...
2017 Nov 29
0
dplyr - add/expand rows
...packages ##########################
>>
>> library(dplyr)
>> library(data.table)
>> library(IRanges)
>> library(microbenchmark)
>>
>> ## prepare example dataset ###########
>>
>> ## use Bert's example, with 2000 stations instead of 2
>> d_df <- data.frame( station = rep(rep(c("one","two"),c(5,4)), 1000L),
>> from = as.integer(c(60,61,71,72,76,60,65,82,83)),
>> to = as.integer(c(60,70,71,76,83,64, 81, 82,83)),
>> record = c("A&qu...
2017 Nov 28
2
dplyr - add/expand rows
Or with the Bioconductor IRanges package:
df <- with(input, DataFrame(station, year=IRanges(from, to), record))
expand(df, "year")
DataFrame with 24 rows and 3 columns
station year record
<character> <integer> <character>
1 07EA001 1960 QMS
2 07EA001 1961 QMC
3 07EA001 1962 QMC
4