I have a data frame that contains a date column that is in integer type. I also want to divide price in range of 10,000 and then count frequency which falls in that month
> df
date values price
11/25/18 a 10000
11/30/18 b 30500
12/4/18 a 20000
12/5/18 b 65000
12/5/18 a 50000
12/6/18 b 35000
12/6/18 c 40000
12/6/18 a 45000
12/6/18 a 30000
12/7/18 b 80000
12/7/18 c 85000
12/7/18 a 90000
12/9/18 b 20000
12/12/18 a 32500
12/12/18 c 40200
12/13/18 b 56000
1/9/19 a 82000
1/9/19 c 63000
1/9/19 b 20000
1/10/19 d 25000
1/10/19 d 34000
1/10/19 d 13020
1/10/19 a 50000
1/11/19 c 24300
1/11/19 d 40000
2/1/19 a 95000
2/10/19 a 20000
2/13/19 b 10000
3/14/19 d 30000
3/17/19 c 45000
5/4/19 d 18000
5/5/19 c 12000
5/6/19 d 90000
5/31/19 a 90000
I was trying this code but I am not able to aggregate in month
df %>%
group_by(date) %>%
count(values)
From this, I am getting the frequency for daily
group_by(month = month(date)) %>%
count(values)
When I was trying this code to aggregate date in month then I was getting following error
(Error in as.POSIXlt.character(as.character(x), ...) : the character string is not in a standard unambiguous format)
And to a group by steps of 10,000 (in the price column) I am using following code
tally(group_by(df, values,
price = cut(price, breaks = seq(10000, 200000, by = 10000)))) %>%
ungroup() %>%
spread(price, n, fill = 0)
Problem:
I am not able to combine this with the code to aggregate date in month and then to spread the data by price groups.
Expected output:
date values 10k-20k 20k-30k 30k-40k 40k-50k 50k-60k 60k-70k 70k-80k 80k-90k
11/18 a 1
11/18 b 1
12/18 a 1 1 1 1 1
12/18 b 1 1 1 1
12/18 c 1 1 1
...