I have the data below, and I'm looking to filter it into some new data frames.
I'm curious if there's a better way of doing it than the following rather than having a separate line for each city and date?
vector.sydney = dplyr::filter(vector, grepl('Sydney', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-07')
vector.adelaide = dplyr::filter(vector, grepl('Adelaide', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-07')
vector.melbourne = dplyr::filter(vector, grepl('Melbourne', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-07')
vector.sydney = dplyr::filter(vector, grepl('Sydney', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-06')
vector.adelaide = dplyr::filter(vector, grepl('Adelaide', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-06')
vector.melbourne = dplyr::filter(vector, grepl('Melbourne', Location)) %>% group_by(Location) %>% filter(Date == '2018-12-06')
I assume I can probably create a list of Locations eg: c("Sydney", "Melbourne", "Adelaide") but I can't figure out how I'd name the outputs.
Can anyone please point me in the right direction?
Dateframe
vector = structure(list(Date = c("6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "6-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18", "7-Dec-18"), Delivery = c("12-Jan-19", "22-Jan-19", "31-Jan-19", "19-Jun-19", "25-Jul-19", "7-Aug-19", "8-Aug-19", "9-Aug-19", "22-Aug-19", "27-Aug-19", "28-Aug-19", "29-Aug-19", "30-Aug-19", "3-Sep-19", "2-Oct-19", "17-Jan-19", "19-Jan-19", "8-Feb-19", "9-Feb-19", "8-Jun-19", "20-Jul-19", "7-Aug-19", "1-Oct-19", "11-Oct-19", "16-Oct-19", "25-Oct-19", "31-Oct-19", "2-Nov-19", "12-Nov-19", "19-Nov-19", "12-Jan-19", "22-Jan-19", "31-Jan-19", "8-Jun-19", "19-Jun-19", "25-Jun-19", "25-Jul-19", "7-Aug-19", "27-Aug-19", "28-Aug-19", "29-Aug-19", "30-Aug-19", "3-Sep-19", "2-Oct-19", "31-Oct-19", "12-Jan-19", "22-Jan-19", "31-Jan-19", "19-Jun-19", "25-Jun-19", "25-Jul-19", "7-Aug-19", "8-Aug-19", "9-Aug-19", "22-Aug-19", "27-Aug-19", "28-Aug-19", "29-Aug-19", "30-Aug-19", "2-Oct-19", "17-Jan-19", "8-Feb-19", "9-Feb-19", "8-Jun-19", "20-Jul-19", "7-Aug-19", "1-Oct-19", "11-Oct-19", "16-Oct-19", "25-Oct-19", "26-Oct-19", "31-Oct-19", "2-Nov-19", "12-Nov-19", "19-Nov-19", "12-Jan-19", "22-Jan-19", "31-Jan-19", "5-Jun-19", "8-Jun-19", "19-Jun-19", "25-Jun-19", "25-Jul-19", "7-Aug-19", "27-Aug-19", "28-Aug-19", "29-Aug-19", "30-Aug-19", "2-Oct-19", "31-Oct-19"), Item.No = c(675L, 440L, 648L, 29L, 605L, 511L, 686L, 656L, 229L, 92L, 331L, 384L, 379L, 332L, 461L, 84L, 418L, 535L, 254L, 90L, 721L, 984L, 342L, 197L, 562L, 327L, 991L, 225L, 514L, 34L, 790L, 675L, 95L, 195L, 407L, 495L, 187L, 529L, 914L, 728L, 839L, 981L, 30L, 728L, 610L, 218L, 265L, 890L, 127L, 2L, 412L, 800L, 65L, 358L, 8L, 737L, 966L, 778L, 617L, 984L, 280L, 374L, 113L, 101L, 310L, 389L, 426L, 572L, 925L, 972L, 611L, 672L, 362L, 145L, 963L, 595L, 186L, 640L, 359L, 714L, 898L, 985L, 93L, 324L, 208L, 629L, 969L, 622L, 235L, 411L), Rank = c(3L, 8L, 7L, 6L, 9L, 5L, 13L, 14L, 11L, 12L, 4L, 2L, 10L, 15L, 1L, 14L, 10L, 11L, 7L, 9L, 13L, 2L, 1L, 6L, 15L, 5L, 4L, 12L, 3L, 8L, 4L, 8L, 6L, 15L, 7L, 12L, 9L, 3L, 10L, 5L, 2L, 13L, 14L, 1L, 11L, 3L, 7L, 8L, 6L, 15L, 9L, 5L, 13L, 14L, 11L, 12L, 4L, 2L, 10L, 1L, 13L, 12L, 6L, 10L, 14L, 1L, 2L, 7L, 11L, 5L, 15L, 3L, 9L, 4L, 8L, 4L, 7L, 8L, 15L, 14L, 6L, 11L, 9L, 3L, 10L, 5L, 2L, 12L, 1L, 13L), Location = c("Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Sydney", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne", "Melbourne")), class = "data.frame", row.names = c(NA, -90L))
vector
isn't complete. It's missing some brackets maybe – Ronak Shahfilter(Date %in% c("2018-12-06","2018-12-07"), grepl("Sydney|Adelaide|Melbourne", Location)) %>% group_by(Location, Date) %>% "something"
. (Regardless, you can reduce each vector by moving thefilter(Date==...)
to within the first one, as infilter(vec, grepl(...), Date==...)
.) – r2evans