This data in json
format. To make it readable you should replace '
by "
as follows firstly,
data2 <- gsub("'", '"', data)
Then we can read it by,
library(jsonlite)
out <- do.call(rbind,lapply(data2, function(x)
do.call(rbind,fromJSON(x))))
[,1]
United States 1
Sweden 1
USA 1
Brazil 1
Germany 1
United States 1
Japan 1
Canada 1
Germany 1
Italy 1
Iran 1
Austria 1
Poland 1
Tunisia 1
From this point on, it is nothing but the data arrangement. You can use whatever you want. I prefer the Base R
as usual,
out <- rowsum(out[,1], row.names(out))
Finally,
head(out[order(-out[,1]),],5)
gives,
United States Germany Belgium Austria Brazil
5 4 2 1 1
Data:
data <- c("{'United States': 1}", "{'Sweden': 1}", "{'USA': 1}", "{'Brazil': 1}", "{'Germany': 1, 'United States': 1}", "{'Japan': 1, 'Canada': 1, 'Germany': 1, 'Italy': 1, 'Iran': 1}", "{'Austria': 1}", "{'Poland': 1}", "{'Tunisia': 1}", "{'United States': 1}", "{'Germany': 1}", "{'Spain': 1, 'Norway': 1}", "{'United States': 1}", "{'Kuwait': 1}", "{'United States': 1}", "{'India': 1}", "{'Belgium': 1}", "{'SungKyunKwan Univ.': 1, 'Sejong Univ.': 1, 'Kwangwoon Univ.': 1, 'Chungcheong College': 1}", "{'R.L.': 1}", "{'United Kingdom': 1, 'Germany': 1, 'Belgium': 1}" )