-1

I got 2 dataframes. dataframe1 has the full dataset and dataframe2 has the date (without duplicate) in it. The dataframe1 contains also the date, but with duplicates. With the another condition like Clicked.on.Ad the value is 0 or 1. I want to count out on that specific date inside dataframe2, count out on that day got how many Click.on.Ad == 1.

for example:

dataframe1

date          Clicked.on.Ad
2012-03-29    0
2012-03-29    1
2012-03-29    1
2012-05-17    0
2012-04-30    1

dataframe2

date
2012-01-05
2012-03-29
2012-04-30
2012-05-17

wanted output

date          count.clicked.on.ad
2012-03-29    2
2012-04-30    1
2012-05-17    0
Jaap
  • 81,064
  • 34
  • 182
  • 193
LonelyToh
  • 15
  • 1
  • 8
  • 1
    You want to sum by groups. See https://stackoverflow.com/questions/1660124/how-to-sum-a-variable-by-group. – PaSTE Feb 08 '18 at 07:15

1 Answers1

1

You could do it using dplyr. The piping framework of dplyr is very easy to understand and you can do complex data manipulation using it.

library(dplyr)
dataframe1 %>% 
  group_by(date) %>% 
  summarise(count.clicked.on.ad = sum(Clicked.on.Ad))
LonelyToh
  • 15
  • 1
  • 8