search for: fun_martin

Displaying 4 results from an estimated 4 matches for "fun_martin".

2017 Nov 29
0
dplyr - add/expand rows
...ataFrame(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(.$from, .$to)) ) } ## Martin - Map fun_martin <- function(d) { d$year <- with(d, Map(seq, from, to)) res0 <- with(d, Map(data.frame, station=station, record=record, year=year, MoreArgs = list(stringsAsFactors = FALSE))) do.call(rbind,...
2017 Nov 29
2
dplyr - add/expand rows
...;year") > } > > ## Jim - dplyr > fun_jim <- function(d) { > ? d %>% > ??? rowwise() %>% > ??? do(tibble(station = .$station, > ????????????? record = .$record, > ????????????? year = seq(.$from, .$to)) > ??? ) > } > > ## Martin - Map > fun_martin <- function(d) { > ? d$year <- with(d, Map(seq, from, to)) > ? res0 <- with(d, Map(data.frame, > ????????????????????? station=station, > ????????????????????? record=record, > ????????????????????? year=year, > ????????????????????? MoreArgs = list(stringsAsFactors...
2017 Nov 29
0
dplyr - add/expand rows
...yr >> fun_jim <- function(d) { >> d %>% >> rowwise() %>% >> do(tibble(station = .$station, >> record = .$record, >> year = seq(.$from, .$to)) >> ) >> } >> >> ## Martin - Map >> fun_martin <- function(d) { >> d$year <- with(d, Map(seq, from, to)) >> res0 <- with(d, Map(data.frame, >> station=station, >> record=record, >> year=year, >> MoreArgs...
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