Spread with duplicate identifiers (using tidyverse and %>%) [duplicate]

We can use tidyverse. After grouping by ‘start_end’, ‘id’, create a sequence column ‘ind’ , then spread from ‘long’ to ‘wide’ format library(dplyr) library(tidyr) df %>% group_by(start_end, id) %>% mutate(ind = row_number()) %>% spread(start_end, date) %>% select(start, end) # id start end #* <int> <fctr> <fctr> #1 2 1994-05-01 1996-11-04 #2 4 1979-07-18 NA #3 … Read more

combine two data frames with all posible combinations

With this particular example I think you can just use the merge function. As a standard its arguments all.x and all.y are set to TRUE, so it automatically creates all combinations since the dataframes do not have any variables or values in common. df <-data.frame(a=letters[1:10] ) df1<-data.frame(one=1:10) dfcomb <- merge(df,df1) dim(dfcomb) [1] 100 2 #gives … Read more