[R] Problem reading mixed CSV file

Berend Hasselman bhh at xs4all.nl
Mon Mar 26 08:26:55 CEST 2012


On 26-03-2012, at 08:16, Ashish Agarwal wrote:

> Why does the output in the following say 2 and not 6?
> 
>> count.fields(textConnection("LL1532Ap,ABC# Depot-A+,,1971,8,2
> + LL1532Ap,ABC# Depot-A+,Bhutan,1971,6,1
> + LL1532Ap,ABC# Depot-A+,China,1971,17,1
> + LL1532Ap,ABC# Depot-A+,China,1971,33,1
> + LL1532Ap,ABC# Depot-A+,HongKong,1971,16,2
> + LL1532Ap,ABC# Depot-A+,HongKong,1971,17,1
> + LL1532Ap,ABC# Depot-A+,HongKong,1971,22,1
> + LL1532Ap,ABC# Depot-A+,HongKong,1971,49,1
> + LL1532Ap,ABC# Depot-A+,Kazakhstan,1971,20,1
> + LL1532Ap,ABC# Depot-A+,Kazakhstan,1971,27,1
> + LL1532Ap,ABC# Depot-A+,Kazakhstan,1971,33,1
> + LL1532Ap,ABC# Depot-A+,Kazakhstan,1973,15,1
> + LL1532Ap,ABC# Depot-A+,Romania-Europe,1971,10,1
> + LL1532Ap,ABC# Depot-A+,Romania-Europe,1973,4,1
> + LL1532Ap,ABC# Depot-A+,Sanchez-America,1973,9,1
> + LL1532An,ABC# Depot-A-,,1971,8,2"),sep=",")
> [1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
>> 
> 


Have you done

?count.fields

and read what it says about the argument "sep" and the default?

So if a comma is the separator what value would you give sep?

Berend



More information about the R-help mailing list