I'm very new to use R language and have some problems sorting the data below to make visualization.
I have a list as follows:
week city price
1 1 newyork 100
2 1 paris 120
3 1 barcelona 130
4 2 paris 100
5 2 barcelona 90
6 2 newyork 80
7 3 newyork 70
8 3 paris 60
9 3 barcelona 50
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
I would like to make the list to a matrix like below
week1 week2 week3 week4 .....
barcelona 130 90
paris 120 100
newyork 100 80
What is the most efficient way to do this?
I would ideally group the cities as row names, then week numbers as columns and match the price accordingly. I don't know the efficient way to do this yet. I would appreciate your help.
** the data type is list ** week: chr, city: Factor, price: num