I want to get a summary of min(cost) per country over the years with the specific airport. The dataset looks like this (around 1000 rows with multiple airports per country)
airport country cost year
ORD US 500 2010
SFO US 800 2010
LHR UK 250 2010
CDG FR 300 2010
FRA GR 200 2010
ORD US 650 2011
SFO US 500 2011
LHR UK 850 2011
CDG FR 350 2011
FRA GR 150 2011
ORD US 250 2012
SFO US 650 2012
LHR UK 350 2012
CDG FR 450 2012
FRA GR 100 2012
The code below gets me summary of min(cost) per country
ddply(df,c('country'), summarize, LowestCost = min(cost))
When I try to display min(cost) of the country along with the specific airport, I just get one airport listed
ddply(df,c('country'), summarize, LowestCost = min(cost), AirportName = df[which.min(df[,3]),1])
The output should look like below
country LowestCost AirportName
US 250 ORD
UK 250 LHR
FR 300 CDG
GR 100 FRA
But instead it looks like this
country LowestCost AirportName
US 250 ORD
UK 250 ORD
FR 300 ORD
GR 100 ORD
Any help is appreciated