Displaying 4 results from an estimated 4 matches for "d_tbl".
Did you mean:
d_tag
2017 Nov 29
0
dplyr - add/expand rows
...stringsAsFactors = FALSE)
stations <- rle(d_df$station)
stations$value <- gsub(
" ", "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)...
2017 Nov 29
2
dplyr - add/expand rows
...ons <- rle(d_df$station)
> stations$value <- gsub(
> ? " ", "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 =...
2017 Nov 29
0
dplyr - add/expand rows
...>> stations$value <- gsub(
>> " ", "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...
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