简体   繁体   English

将 csv 导入 r 时 a-hat 是什么意思(以及如何摆脱它)?

[英]What's an a-hat mean when importing a csv into r (and how do I get rid of it)?

I'm importing a csv into r and there are a-hats (an a with a circumflex / up carat above it) all over the place that don't exist in the raw data.我正在将一个 csv 导入到 r 中,并且在原始数据中不存在的地方到处都是 a-hats(一个带有抑扬符/向上克拉的 a)。

Does anyone know what they are and how to get rid of them?有谁知道它们是什么以及如何摆脱它们?

Here is the dput(head(df)) result @foc suggested I supply:这是@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")

Not sure if this is what you want:不确定这是否是您想要的:

data example:数据示例:

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")

remove the character:删除字符:

df[] <- lapply(df, gsub, pattern='a€¦', replacement='')

results:结果:

df
                         V1      V2     V3  V4   V5  V6      V7     V8  V9  V10 V11  V12   V13
1                                                                                             
2 Race3 and Hispanic Origin                                                                   
3                     White 245,985 27,113 547 11.0 0.2 247,272 26,436 714 10.7 0.3 -677 *-0.3
4       White, not Hispanic 195,221 17,263 493  8.8 0.3 195,256 16,993 571  8.7 0.3 -270  -0.1
5                     Black  41,962  9,234 388 22.0 0.9  42,474  8,993 373 21.2 0.9 -241  -0.8
6                     Asian  18,879  1,908 175 10.1 0.9  19,475  1,953 190 10.0 1.0   45  -0.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在R中使用plot()时如何摆脱网格? - How do I get rid of grids when using plot() in R? 在包装中使用ddply时,如何摆脱R CMD检查生成的NOTE? - How do I get rid of the NOTE's generated by R CMD check when using for example ddply in my package? 在R中我的字符向量之上的这个单词是什么?如何摆脱它 - What is this word on top of my character vector in R and how do I get rid of it 如何去掉 R shiny 中的某个列? - How do I get rid of a certain column in R shiny? 如何摆脱 R 中具有相同名称的多个列? - How do I get rid of multiple columns with the same name in R? 如何摆脱R生成的文件名中的文件扩展名(.CSV) - How to get rid of file extensions (.CSV) in a file name that is generated by R 将 CSV 导入 R 时,如何生成名称为 CSV 的列? - When importing CSV into R how to generate column with name of the CSV? 将CSV导入R后,标题不是我想要的 - After importing CSV into R, the headers are not what I want R:串联CSV文件并获取1个变量的均值时,我得到1个文件的正确答案,但序列不正确 - R: When concatenating CSV files and getting the mean for 1 variable I get correct answer for 1 file but incorrect for sequence 如何从csv获取数据以将其读入R中的函数? - How do I get data from a csv to be read into a function in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM