[R] Problem reading mixed CSV file
Berend Hasselman
bhh at xs4all.nl
Mon Mar 26 08:35:10 CEST 2012
On 26-03-2012, at 08:26, Berend Hasselman wrote:
>
> 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?
Sorry I should have had a closer look at what you had done.
But still ?count.fields should have given you a pointer.
Look at what it says in the entry for argument "comment.char".
You have a character # in your text.
Set comment.char to something other than # .
Berend
More information about the R-help
mailing list