Hi guys,
I am quite new to R and probably have a tricky question for you that might also challenge some more advanced coders.
I want to create a variable that tells me, if any of the Friends of the persons come from the same country, then how much.
So in case of "Alex" the new column in the dataset should show 51% because 51% of his friends come from the same country, in this case "Austria"
In the case of Bob the column should show me in Bob's row that 10% come from the same country.
In case of Felicia it would be 0% because her friends do not come from the same country
Person Name | Person Country | Most friends come from | Most friends come from percent | Second most friends come from | Second most friends come from percent | Third most friends come from | Third most friends come from percent |
---|---|---|---|---|---|---|---|
Alex | Austria | Austria | 51,00% | Sweden | 12,00% | Norway | 5,00% |
Bob | Denmark | United States | 14,00% | Denmark | 10,00% | Spain | 5,00% |
Charlie | France | France | 30,00% | Spain | 15,00% | United States | 12,00% |
Diana | The Netherlands | Spain | 32,00% | Sweden | 28,00% | United States | 10,00% |
Eva | Finland | Sweden | 60,00% | United States | 20,00% | Finland | 10,00% |
Felicia | Germany | Austria | 24,00% | United States | 23,00% | Spain | 17,00% |
I would really appreciate it if you could help me with these lines of code because as a beginner I am quite overwhelmed with this task.
Thank you very much in advance,
Lukas