如何用逗号(,)作为R中的分隔符读取csv文件

时间:2016-01-17 02:24:58

标签: r import-from-csv

我试图在R.(scores.csv)中读取此csv文件

ALVO,P,Prediction,fold
1,0.9079557994069131,"1",0
1,0.4323657303144317,"0",0
1,0.9944246408740756,"1",0
1,0.8025072441292207,"1",0
1,0.8687043760021418,"1",0
1,0.8728815023271057,"1",0
1,0.9998157504312343,"1",0
1,0.6610699528239422,"1",0
1,0.9994385364719802,"1",0

我试过这个:

  

结果< - read.csv(" C:/scores.csv" ;, header = TRUE,sep =",",quote =" \&# 34;&#34)

这样:

  

结果< - read.csv(" C:/scores.csv")

它没有工作,我得到P,预测,用NA值折叠

  

头(结果)

但我得到了这个:

                        ALVO  P Prediction fold
1 1,0.9079557994069131,"1",0 NA         NA   NA
2 1,0.4323657303144317,"0",0 NA         NA   NA
3 1,0.9944246408740756,"1",0 NA         NA   NA
4 1,0.8025072441292207,"1",0 NA         NA   NA
5 1,0.8687043760021418,"1",0 NA         NA   NA
6 1,0.8728815023271057,"1",0 NA         NA   NA

有人已经这样做了吗?

请帮忙!

1 个答案:

答案 0 :(得分:2)

Unix cat输出如下:

> cat input.csv 
ALVO,P,Prediction,fold
1,0.9079557994069131,"1",0
1,0.4323657303144317,"0",0
1,0.9944246408740756,"1",0
1,0.8025072441292207,"1",0
1,0.8687043760021418,"1",0
1,0.8728815023271057,"1",0
1,0.9998157504312343,"1",0
1,0.6610699528239422,"1",0
1,0.9994385364719802,"1",0

R输出低于:

read.csv('input.csv')
  ALVO         P Prediction fold
1    1 0.9079558          1    0
2    1 0.4323657          0    0
3    1 0.9944246          1    0
4    1 0.8025072          1    0
5    1 0.8687044          1    0
6    1 0.8728815          1    0
7    1 0.9998158          1    0
8    1 0.6610700          1    0
9    1 0.9994385          1    0