I have two columns, first is the function of the Business (Upstream, Downstream , Midstream etc) and the other is the city those functions operate in. There are a ton of other functions amd cities but I have made it smaller here and it looks something like this:
Function City
DownStream Edmonton
Downstream Edmonton
upstream Edmonton
Upstream Calgary
Midstream Calgary
Midstream Calgary
Midtream Edmonton
Upstream Vancouver
I know the unique() function will return the unqiue values I am looking for, however I am having trouble creating something that will group the Function column and then listing the unique Cities for each Function.
Something like this as the end results:
Functions City
Downstream Edmonton
Midstream Edmonton
Calgary
Upstream Edmonton
Calgary
Vancouver
Here is some sample data to work from
# Create sample data
Function=c("DownStream", "DownStream", "Upstream", "Upstream", "Midstream",
"Midstream", "Midstream", "Upstream")
City=c("Edmonton", "Edmonton", "Edmonton", "Calgary","Calgary", "Calgary",
"Edmonton", "Vancouver")
df <- data.frame(Function, City)