Im trying to generate sentences from a dataframe Below is the dataframe
# Code
mycode <- c("AAABBB", "AAABBB", "AAACCC", "AAABBD")
mycode <- sample(mycode, 20, replace = TRUE)
# Date
mydate <-c("2016-10-17","2016-10-18","2016-10-19","2016-10-20")
mydate <-sample(mydate, 20, replace = TRUE)
# resort
myresort <-c("GB","IE","GR","DK")
myresort <-sample(myresort, 20, replace = TRUE)
# Number of holidaymakers
HolidayMakers <- sample(1000, 20, replace = TRUE)
mydf <- data.frame(mycode,
mydate,
myresort,
HolidayMakers)
So if we take mycode
as an example, I want to create a sentence like "For the code mycode
, the biggest destinations are myresorts
where the top days of visiting were mydate
with a total of HolidayMakers
"
If we assume that there are multiple lines per code. What i want is a single sentence where for example instead of having one sentence per mydate
and myresort
, i would like to say something like
"For the code AAABBB, the biggest destinations are GB,GR,DK,IE where the top days of visiting were 2016-10-17,2016-10-18,2016-10-19 with a total of 650"
The 650 would basically be a sum of all the holiday makers for all those countries for those days per mycode
Any anyone help?
Thank you for your time