0

I need to build a "profile" of a data set, showing the number of data entries that lie between two values. I have been able to achieve the result using the "group_by" function, however the resultant output is not in a format that I can use further down my workflow. Here is that output:

Example 1

What I need, is something that looks like this:

Example 2

The "Data Count" column, I've not been able to populate but is there for illustration.

The code I am using is as follows;

library(formattable)
PML_Start = 0
PML_Max = 100000000
PML_Interval = 5000000 

Lower_Band <- currency(seq(PML_Start, PML_Max-PML_Interval, PML_Interval),digits=0)
Upper_Band <- currency(seq(PML_Start+PML_Interval,PML_Max,PML_Interval),digits = 0)

PML_Profile <- data.frame("Lower Band"=Lower_Band,"Upper Band"=Upper_Band,"Data Count")

I know cannot figure out how to further populate this table. I gave this a go, but didn't really believe it would work.

PML_Profile <- Profiles_on_Data_Provided_26_9_17 %>%
  group_by (Lower_Band) %>%
  summarise("Premium" = sum(Profiles_on_Data_Provided_26_9_17$`Written Premium - Total`))

Any thoughts?

kath
  • 7,624
  • 17
  • 32
Dant19
  • 1
  • 2
  • Use the `labels` argument in `cut` – Mikko Marttila Feb 15 '18 at 10:13
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Feb 15 '18 at 10:14
  • `Error in currency(seq(PML_Start, PML_Max - PML_Interval, PML_Interval), : could not find function "currency"` – Roman Feb 15 '18 at 10:23
  • Hey Jimbou - you need the "formattable" package installed. – Dant19 Feb 15 '18 at 10:26

0 Answers0