Re: [R] dplyr - add/expand rows

2017-11-29 Thread Martin Morgan
On 11/29/2017 05:47 PM, Tóth Dénes wrote: Hi Martin, On 11/29/2017 10:46 PM, Martin Morgan wrote: On 11/29/2017 04:15 PM, Tóth Dénes wrote: Hi, A benchmarking study with an additional (data.table-based) solution. I don't think speed is the right benchmark (I do agree that correctness is!)

Re: [R] dplyr - add/expand rows

2017-11-29 Thread Tóth Dénes
Hi Martin, On 11/29/2017 10:46 PM, Martin Morgan wrote: On 11/29/2017 04:15 PM, Tóth Dénes wrote: Hi, A benchmarking study with an additional (data.table-based) solution. I don't think speed is the right benchmark (I do agree that correctness is!). Well, agree, and sorry for the wording.

Re: [R] dplyr - add/expand rows

2017-11-29 Thread Martin Morgan
On 11/29/2017 04:15 PM, Tóth Dénes wrote: Hi, A benchmarking study with an additional (data.table-based) solution. I don't think speed is the right benchmark (I do agree that correctness is!). For the R-help list, maybe something about least specialized R knowledge required would be appro

Re: [R] dplyr - add/expand rows

2017-11-29 Thread Tóth Dénes
Hi, A benchmarking study with an additional (data.table-based) solution. Enjoy! ;) Cheers, Denes -- ## packages ## library(dplyr) library(data.table) library(IRanges) library(microbenchmark) ## prepare example dataset ### ## use Be

Re: [R] dplyr - add/expand rows

2017-11-28 Thread Bert Gunter
Bill et al.: Yes, I see it now. Thank you for the correction. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 28, 2017 at 1:42 PM, William D

Re: [R] dplyr - add/expand rows

2017-11-28 Thread William Dunlap via R-help
Bert wrote ... Bill's solution seems to be for only one station. No, it works for any number of stations. Bill Dunlap TIBCO Software wdunlap tibco.com On Sun, Nov 26, 2017 at 11:10 AM, Bert Gunter wrote: > To David W.'s point about lack of a suitable reprex ("reproducible > example"), Bill's

Re: [R] dplyr - add/expand rows

2017-11-28 Thread Michael Lawrence
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 1 07EA001 1960 QMS 2 07EA001 1961 QMC 3 0

Re: [R] dplyr - add/expand rows

2017-11-28 Thread Martin Morgan
On 11/26/2017 08:42 PM, jim holtman wrote: try this: ## library(dplyr) input <- tribble( ~station, ~from, ~to, ~record, "07EA001" ,1960 , 1960 , "QMS", "07EA001" , 1961 , 1970 , "QMC", "07EA001" ,1971 , 1971 , "QMM", "07EA0

Re: [R] dplyr - add/expand rows

2017-11-26 Thread jim holtman
try this: ## library(dplyr) input <- tribble( ~station, ~from, ~to, ~record, "07EA001" ,1960 , 1960 , "QMS", "07EA001" , 1961 , 1970 , "QMC", "07EA001" ,1971 , 1971 , "QMM", "07EA001" ,1972 , 1976 , "QMC", "07EA001" ,1

Re: [R] dplyr - add/expand rows

2017-11-26 Thread Bert Gunter
To David W.'s point about lack of a suitable reprex ("reproducible example"), Bill's solution seems to be for only one station. Here is a reprex and modification that I think does what was requested for multiple stations, again using base R and data frames, not dplyr and tibbles. First the reprex

Re: [R] dplyr - add/expand rows

2017-11-26 Thread David Winsemius
> On Nov 25, 2017, at 11:18 AM, Hutchinson, David (EC) > wrote: > > I have a returned tibble of station operational record similar to the > following: > >> data.collection > # A tibble: 5 x 4 > STATION_NUMBER YEAR_FROM YEAR_TO RECORD > > 107EA001 1960196

Re: [R] dplyr - add/expand rows

2017-11-25 Thread William Dunlap via R-help
dplyr may have something for this, but in base R I think the following does what you want. I've shortened the name of your data set to 'd'. i <- rep(seq_len(nrow(d)), d$YEAR_TO-d$YEAR_FROM+1) j <- sequence(d$YEAR_TO-d$YEAR_FROM+1) transform(d[i,], YEAR=YEAR_FROM+j-1, YEAR_FROM=NULL, YEAR_TO=NULL)

[R] dplyr - add/expand rows

2017-11-25 Thread Hutchinson, David (EC)
I have a returned tibble of station operational record similar to the following: > data.collection # A tibble: 5 x 4 STATION_NUMBER YEAR_FROM YEAR_TO RECORD 107EA001 19601960QMS 207EA001 19611970QMC 307EA001 1971197