从UN数据库导入CSV数据

时间:2017-03-28 13:14:03

标签: r csv read.table read.csv

我正在尝试从联合国难民署http://popstats.unhcr.org/en/time_series

输入难民数据

我导出数据并尝试使用我之前从未遇到过问题的read.csv函数导入数据并收到以下错误代码

un <- read.csv("un.csv", na.strings = "..")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  more columns than column names

for ref我用word打开了csv文件,这是它的格式;

""Extracted from the UNHCR Population Statistics Reference Database","United Nations High Commissioner for Refugees"
"Date extracted: 2015-09-18 04:37:24 +02:00"

Year,"Country / territory of asylum/residence",Origin,"Population type",Value
1951,Australia,Various/Unknown,"Refugees (incl. refugee-like situations)",180000
1951,Austria,Various/Unknown,"Refugees (incl. refugee-like situations)",282000
1951,Belgium,Various/Unknown,"Refugees (incl. refugee-like situations)",55000
1951,Canada,Various/Unknown,"Refugees (incl. refugee-like situations)",168511
1951,Switzerland,Various/Unknown,"Refugees (incl. refugee-like situations)" 

所以看起来格式正确所以我对于出了什么问题感到有点失落。

感谢您的帮助

克里斯

1 个答案:

答案 0 :(得分:0)

您的数据存在拼写错误。应该是这样的:

un = structure(list(Year = c(1951L, 1951L, 1951L, 1951L, 1951L), Country...territory.of.asylum.residence = structure(1:5, .Label = c("Australia", 
"Austria", "Belgium", "Canada", "Switzerland"), class = "factor"), 
    Origin = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Various/Unknown", class = "factor"), 
    Population.type = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Refugees (incl. refugee-like situations)", class = "factor"), 
    Value = c(180000, 282000, 55000, 168511, NA)), .Names = c("Year", 
"Country...territory.of.asylum.residence", "Origin", "Population.type", 
"Value"), class = "data.frame", row.names = c(NA, -5L))

然后您可以使用 read.table()

轻松导入
df=read.table("un.csv", header = T, sep=",")
相关问题