Hey Ive just started learning R. I wanted to ask how i can find the maximum value in a vector based for combination of 2 vectors in a dataframe. For instance, I want to find the five maximum avg price . I have a data frame with about 7 columns, 3 of them being average price, city and year. The year is obviously recurrent and ranges from 2000 to 2009. The data also has various NA's in different columns and rows.
The Data Frame looks something like this:
avgprice year city
12 2000 Jersey City
45 2001 Hoboken
NA 2000 Hoboken
34 2000 evanston
67 2001 abilene
89 2001 elizabeth
45 2000 delhi
98 2000 delhi
I want the answer to look like
year city avgprice
2000 jersey city 12
2000 evanston 34
2000 delhi 98
2001 hoboken 45
2001 elizabeth 89
2001 abilene 67
I tried with the following code but I think I'm messing up something. I tried to create df using split by year and then used an aggregate function.
df<-split(tx.house.sales, tx.house.sales$year)
re<-aggregate(avgprice~city, df, FUN=max)
Thank you :)