我使用包读取器。当我用分号分隔符读取csv文件时:
library(readr)
read_csv2("A;B\n1.3;alpha\n2.345;beta", col_types = "dc")
这是我得到的答案:
Warning: 2 parsing failures.
row col expected actual
1 A no trailing characters .3
2 A no trailing characters .345
A B
1 NA alpha
2 NA beta
换句话说,数字1.3和2.345无法识别。 使用逗号分隔符一切都很好:
read_csv("A,B\n1.3,alpha\n2.345,beta", col_types = "dc")
A B
1 1.300 alpha
2 2.345 beta
你能重现这个吗?你知道它来自哪里吗? 谢谢你的帮助。
这是我的会话信息:
sessionInfo()
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] readr_0.2.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.4
答案 0 :(得分:1)
实际上,您应该使用read_delim()
选项delim = ";"
:
library(readr)
read_delim("A;B\n1.3;alpha\n2.345;beta", col_types = "dc", delim = ";")
答案 1 :(得分:0)
定义分隔符以告诉R要查找的内容:
库(readr)
read_csv2("A;B\n1.3;alpha\n2.345;beta", col_types = "dc", sep = ";")
这将告诉它打破;