I have two data frames
A:
customer application_date
1        2010-05-08
2        2012-08-08
3        2013-06-23
and B:
customer date        balance
1        2009-01-02  2500
1        2009-12-24  3000
2        2011-11-11  1200  
2        2012-05-20  1900
3        2013-03-21  5500
3        2013-06-05  4500
I need to merge them together so that date in table A would be closest to date in table B (by customer)
Result:
customer        application_date  date        balance
1               2010-05-08        2009-12-24  3000
2               2012-08-08        2012-05-20  1900
3               2013-06-23        2013-06-05  4500
How could I merge those two tables correctly?
Code for example tables:
A <- data.frame(customer = c(1,2,3),
                application_date = c("2010-05-08", "2012-08-08", "2013-06-23"))
B <- data.frame(customer = c(1,1,2,2,3,3),
                date = c("2009-01-02", "2009-12-24", "2011-11-11", "2012-05-20", "2013-03-21", "2013-06-05"),
                balance = c(2500, 3000, 1200, 1900, 5500, 4500))