1

sometimes when I use google apis in R some dates are ommited when there is no interaction I would like report them as NAs. For that purpose I would like to combine a predefined date range 2015-02-13 - 2015-02-16 for example, after the query is used. For example:

   range               df

  dates              dates         A 

 2015-02-13          2015-02-13    4  
 2015-02-14          2015-02-14    3  
 2015-02-15          2015-02-16    5
 2015-02-16         

required output:

     dates       A
 2015-02-13      4     
 2015-02-14      3  
 2015-02-15      NA    
 2015-02-16      5

 Data:

 A <- c(4,3,5)
 dates <- as.Date(as.character(c("2015-02-13","2015-02-14","2015-02-16")))

 df<-data.frame(dates,A)
 range<- seq(as.Date("2015-02-13"), as.Date("2015-02-16"), by = "days")

 test<-rbind(range,df)
 library(plyr)

 test<-rbind.fill(range,df)

But that doesnt do the trick.

  • Just make `range` a `data.frame` and then just an outer join `range <- data.frame(dates = seq(as.Date("2015-02-13"), as.Date("2015-02-16"), by = "days")) ; merge(range, df, by = "dates", all = TRUE)` – David Arenburg Oct 26 '15 at 15:50

1 Answers1

2

what about

merge(..., all.x=TRUE)

read the documantation of merge()

jogo
  • 12,469
  • 11
  • 37
  • 42