Displaying 4 results from an estimated 4 matches for "fun_michael".
2017 Nov 29
0
dplyr - add/expand rows
...l(rbind,out),
row.names = NULL,
stringsAsFactors = FALSE)
}
## Bill - transform
fun_bill <- function(d) {
i <- rep(seq_len(nrow(d)), d$to-d$from+1)
j <- sequence(d$to-d$from+1)
transform(d[i,], year=from+j-1, from=NULL, to=NULL)
}
## Michael - IRanges
fun_michael <- function(d) {
df <- with(d, DataFrame(station, record, year=IRanges(from, to)))
expand(df, "year")
}
## Jim - dplyr
fun_jim <- function(d) {
d %>%
rowwise() %>%
do(tibble(station = .$station,
record = .$record,
year = seq...
2017 Nov 29
2
dplyr - add/expand rows
...???? stringsAsFactors = FALSE)
> }
>
> ## Bill - transform
> fun_bill <- function(d) {
> ? i <- rep(seq_len(nrow(d)), d$to-d$from+1)
> ? j <- sequence(d$to-d$from+1)
> ? transform(d[i,], year=from+j-1, from=NULL, to=NULL)
> }
>
> ## Michael - IRanges
> fun_michael <- function(d) {
> ? df <- with(d, DataFrame(station, record, year=IRanges(from, to)))
> ? expand(df, "year")
> }
>
> ## Jim - dplyr
> fun_jim <- function(d) {
> ? d %>%
> ??? rowwise() %>%
> ??? do(tibble(station = .$station,
> ????????...
2017 Nov 29
0
dplyr - add/expand rows
...>>
>> ## Bill - transform
>> fun_bill <- function(d) {
>> i <- rep(seq_len(nrow(d)), d$to-d$from+1)
>> j <- sequence(d$to-d$from+1)
>> transform(d[i,], year=from+j-1, from=NULL, to=NULL)
>> }
>>
>> ## Michael - IRanges
>> fun_michael <- function(d) {
>> df <- with(d, DataFrame(station, record, year=IRanges(from, to)))
>> expand(df, "year")
>> }
>>
>> ## Jim - dplyr
>> fun_jim <- function(d) {
>> d %>%
>> rowwise() %>%
>> do(tibble(...
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