![](/img/trans.png)
[英]Read dataset in R in which comma is used for field separator and decimal point
[英]R: Read in CSV decimal point and comma
我是初学者,我想用两者读取csv文件。 并且是小数点分隔符。 我怎么能在R.谢谢
AllDataxx=read.csv("C:Sample.csv",
header=TRUE,sep=";",dec=", & .")
你恐怕不能开箱即用。 当然,你可以做的是决定你想说什么.
,并使用colClasses
参数来加载,
列作为一个character
。 然后你将使用gsub(pattern=
,replacement='.', x=yourColumnVector)
来改变,
进入.
和as.numeric
将向量转换为numeric
DF = data.frame(a=c(1.1,1.3,1.4),b=c('1,1','1,3','1,6'))
DF
a b
1 1.1 1,1
2 1.3 1,3
3 1.4 1,6
str(DF)
'data.frame': 3 obs. of 2 variables:
$ a: num 1.1 1.3 1.4
$ b: chr "1,1" "1,3" "1,6"
DF$b = as.numeric(gsub(',','.',DF$b))
DF
a b
1 1.1 1.1
2 1.3 1.3
3 1.4 1.6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.