【发布时间】:2018-10-03 19:56:34
【问题描述】:
我正在将一个 csv 导入到 r 中,并且到处都是原始数据中不存在的 a-hats(一个带有抑扬符/向上克拉的 a)。
有谁知道它们是什么以及如何摆脱它们?
这是@foc 建议我提供的 dput(head(df)) 结果:
structure(list(V1 = c("", "Race3 and Hispanic Origin", "Whiteâ\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦",
" White, not Hispanicâ\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦",
"Blackâ\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦",
"Asianâ\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦â\200¦"
), V2 = c("", "", "245,985", "195,221", "41,962", "18,879"),
V3 = c("", "", "27,113", "17,263", "9,234", "1,908"), V4 = c("",
"", "547", "493", "388", "175"), V5 = c("", "", "11.0", "8.8",
"22.0", "10.1"), V6 = c("", "", "0.2", "0.3", "0.9", "0.9"
), V7 = c("", "", "247,272", "195,256", "42,474", "19,475"
), V8 = c("", "", "26,436", "16,993", "8,993", "1,953"),
V9 = c("", "", "714", "571", "373", "190"), V10 = c("", "",
"10.7", "8.7", "21.2", "10.0"), V11 = c("", "", "0.3", "0.3",
"0.9", "1.0"), V12 = c("", "", "-677", "-270", "-241", "45"
), V13 = c("", "", "*-0.3", "-0.1", "-0.8", "-0.1")), row.names = c(NA,
6L), class = "data.frame")
【问题讨论】:
-
寻求帮助时,您应该包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出。这可能是一个编码问题,但由于提供的信息有限,很难确定。您使用的是什么操作系统?文件的编码是什么?您的系统区域设置是什么?
-
@ajbently。拜托,你能再详细一点吗?使用
dput(head(df))并提供一些数据并进一步解释一下您对a-hats 的含义以便为您提供帮助? -
@MrFlick 抱歉,我想不出我能给出什么作为可复制的例子。
-
@ajbentley 可能你的 utf 编码有问题。你用
df1 <- read.csv("C:/Users/user/Desktop/example.csv", header=TRUE, sep=",", fileEncoding = "UTF-8")这样的方式来读取你的csv吗? -
@foc 或多或少。我尝试添加 fileEncoding 但返回:错误 in read.table(file = file, header = header, sep = sep, quote = quote, : no lines available in input