Q:

Convert a key value list to a dataframe

I have a key / value list in R called country :
print(country)
$CAM
[1] 5

$TJK
[1] 1

$SEN
[1] 7

the key is the name of a country and the value an occurence of this one.
And i would like to convert this list as a dataframe like ths  :
  country  occurence
0 CAM      5
0 TJK      1
0 SEN      7

thanks and regards

A:

You can unlist and stack the input-list:
stack(unlist(country))
#  values ind
#1      5 CAM
#2      1 TJK
#3      7 SEN

