search for: fun_bert

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

2017 Nov 29
0
dplyr - add/expand rows
...0", paste0("station", format(1:length(stations$value), width = 6))) d_df$station <- rep(stations$value, stations$lengths) ## prepare tibble and data.table versions d_tbl <- as_tibble(d_df) d_dt <- as.data.table(d_df) ## solutions ########################## ## Bert - by fun_bert <- function(d) { out <- by( d, d$station, function(x) with(x, { i <- to - from +1 data.frame(record =rep(record,i), year =sequence(i) -1 + rep(from,i), stringsAsFactors = FALSE) })) data.frame(station = rep(names(out), sappl...
2017 Nov 29
2
dplyr - add/expand rows
...ength(stations$value), width = 6))) > d_df$station <- rep(stations$value, stations$lengths) > > ## prepare tibble and data.table versions > d_tbl <- as_tibble(d_df) > d_dt <- as.data.table(d_df) > > ## solutions ########################## > > ## Bert - by > fun_bert <- function(d) { > ? out <- by( > ??? d, d$station, function(x) with(x, { > ????? i <- to - from +1 > ????? data.frame(record =rep(record,i), > ???????????????? year =sequence(i) -1 + rep(from,i), > ???????????????? stringsAsFactors = FALSE) > ??? })) > ? da...
2017 Nov 29
0
dplyr - add/expand rows
...gt;> d_df$station <- rep(stations$value, stations$lengths) >> >> ## prepare tibble and data.table versions >> d_tbl <- as_tibble(d_df) >> d_dt <- as.data.table(d_df) >> >> ## solutions ########################## >> >> ## Bert - by >> fun_bert <- function(d) { >> out <- by( >> d, d$station, function(x) with(x, { >> i <- to - from +1 >> data.frame(record =rep(record,i), >> year =sequence(i) -1 + rep(from,i), >> stringsAsFactors = FALSE)...
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