library(tidyverse)
library(lubridate)
df <- tribble(
~date, ~CNGBOND, ~FRGBOND
, "2006-02-15", NA, 3.76
, "2006-03-31", 4.26, NA
, "2006-05-15", NA, 4.25
, "2006-06-30", 4.69, NA
, "2006-08-15", NA, 4.17
, "2006-09-29", 4.08, NA
, "2006-11-15", NA, 4.06
, "2006-12-29", 4.11, NA
)
firstNonNA <- function(x) x[!is.na(x)][1]
df %>%
mutate(date = ymd(date)) %>%
mutate(Quarter = quarter(date, with_year = TRUE)) %>%
group_by(Quarter) %>%
summarise_at(vars(CNGBOND, FRGBOND), firstNonNA)