Errors in reading in txt files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Errors in reading in txt files

lily li
Hi R users,

I have a question about reading from text files. The file has the structure
below:

Time                            Column1   Column2
01.01.2001-12:00:00
01.01.2001-24:00:00        12             11
01.02.2001-12:00:00        13             10
01.02.2001-24:00:00        11             12
01.03.2001-12:00:00        15             11
01.03.2001-24:00:00        16             10
...

I just use the simple script to open it: df = read.table('DATAM', head=T).

But it has the error and thus cannot read the file:
Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
dec,  :
  line 1 did not have 3 elements

How to read it with three fixed columns, and how to read the time format in
the first column correctly? Thanks for your help.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

Berend Hasselman

> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>
> Hi R users,
>
> I have a question about reading from text files. The file has the structure
> below:
>
> Time                            Column1   Column2
> 01.01.2001-12:00:00

This line does not contain 3 elements; only one.
You'll have to fix that line. Delete it, prepend it with a comment character of add enough columns.


Berend

> 01.01.2001-24:00:00        12             11
> 01.02.2001-12:00:00        13             10
> 01.02.2001-24:00:00        11             12
> 01.03.2001-12:00:00        15             11
> 01.03.2001-24:00:00        16             10
> ...
>
> I just use the simple script to open it: df = read.table('DATAM', head=T).
>
> But it has the error and thus cannot read the file:
> Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
> dec,  :
>  line 1 did not have 3 elements
>
> How to read it with three fixed columns, and how to read the time format in
> the first column correctly? Thanks for your help.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

lily li
Thanks, Berend. I thought R can recognize the space automatically, such as
na.strings="", or sep=' '.

On Thu, Dec 14, 2017 at 11:58 AM, Berend Hasselman <[hidden email]> wrote:

>
> > On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
> >
> > Hi R users,
> >
> > I have a question about reading from text files. The file has the
> structure
> > below:
> >
> > Time                            Column1   Column2
> > 01.01.2001-12:00:00
>
> This line does not contain 3 elements; only one.
> You'll have to fix that line. Delete it, prepend it with a comment
> character of add enough columns.
>
>
> Berend
>
> > 01.01.2001-24:00:00        12             11
> > 01.02.2001-12:00:00        13             10
> > 01.02.2001-24:00:00        11             12
> > 01.03.2001-12:00:00        15             11
> > 01.03.2001-24:00:00        16             10
> > ...
> >
> > I just use the simple script to open it: df = read.table('DATAM',
> head=T).
> >
> > But it has the error and thus cannot read the file:
> > Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
> > dec,  :
> >  line 1 did not have 3 elements
> >
> > How to read it with three fixed columns, and how to read the time format
> in
> > the first column correctly? Thanks for your help.
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

Ista Zahn
In reply to this post by Berend Hasselman
On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]> wrote:

>
>> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>>
>> Hi R users,
>>
>> I have a question about reading from text files. The file has the structure
>> below:
>>
>> Time                            Column1   Column2
>> 01.01.2001-12:00:00
>
> This line does not contain 3 elements; only one.
> You'll have to fix that line. Delete it, prepend it with a comment character of add enough columns.

I definitely don't recommend that. Instead, read

?read.table

to learn about the "fill" and "header" arguments.

df = read.table("DATAM", header = TRUE, fill = TRUE)

will probably work.

Best,
Ista


>
>
> Berend
>
>> 01.01.2001-24:00:00        12             11
>> 01.02.2001-12:00:00        13             10
>> 01.02.2001-24:00:00        11             12
>> 01.03.2001-12:00:00        15             11
>> 01.03.2001-24:00:00        16             10
>> ...
>>
>> I just use the simple script to open it: df = read.table('DATAM', head=T).
>>
>> But it has the error and thus cannot read the file:
>> Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
>> dec,  :
>>  line 1 did not have 3 elements
>>
>> How to read it with three fixed columns, and how to read the time format in
>> the first column correctly? Thanks for your help.
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

Berend Hasselman

> On 14 Dec 2017, at 20:01, Ista Zahn <[hidden email]> wrote:
>
> On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]> wrote:
>>
>>> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>>>
>>> Hi R users,
>>>
>>> I have a question about reading from text files. The file has the structure
>>> below:
>>>
>>> Time                            Column1   Column2
>>> 01.01.2001-12:00:00
>>
>> This line does not contain 3 elements; only one.
>> You'll have to fix that line. Delete it, prepend it with a comment character of add enough columns.
>
> I definitely don't recommend that. Instead, read
>
> ?read.table
>
> to learn about the "fill" and "header" arguments.
>
> df = read.table("DATAM", header = TRUE, fill = TRUE)
>
> will probably work.
>

Yes. I agree. It's much better.
I should have experimented some more.

Berend

> Best,
> Ista
>
>
>>
>>
>> Berend
>>
>>> 01.01.2001-24:00:00        12             11
>>> 01.02.2001-12:00:00        13             10
>>> 01.02.2001-24:00:00        11             12
>>> 01.03.2001-12:00:00        15             11
>>> 01.03.2001-24:00:00        16             10
>>> ...
>>>
>>> I just use the simple script to open it: df = read.table('DATAM', head=T).
>>>
>>> But it has the error and thus cannot read the file:
>>> Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
>>> dec,  :
>>> line 1 did not have 3 elements
>>>
>>> How to read it with three fixed columns, and how to read the time format in
>>> the first column correctly? Thanks for your help.
>>>
>>>      [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

MacQueen, Don
In reply to this post by Ista Zahn
In addition to which, I would recommend

df <- read.table("DATAM", header = TRUE, fill = TRUE, stringsAsFactors=FALSE)

and then converting the Time column to POSIXct date-time values using
  as.POSIXct()
specifying the format using formatting codes found in
  ?strptime
because the times are not in the POSIXct default format.


This example might indicate the idea:

> as.POSIXct('2012-10-12 13:14')
[1] "2012-10-12 13:14:00 PDT"
> class(as.POSIXct('2012-10-12 13:14'))
[1] "POSIXct" "POSIXt"

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 12/14/17, 11:01 AM, "R-help on behalf of Ista Zahn" <[hidden email] on behalf of [hidden email]> wrote:

    On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]> wrote:
    >
    >> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
    >>
    >> Hi R users,
    >>
    >> I have a question about reading from text files. The file has the structure
    >> below:
    >>
    >> Time                            Column1   Column2
    >> 01.01.2001-12:00:00
    >
    > This line does not contain 3 elements; only one.
    > You'll have to fix that line. Delete it, prepend it with a comment character of add enough columns.
   
    I definitely don't recommend that. Instead, read
   
    ?read.table
   
    to learn about the "fill" and "header" arguments.
   
    df = read.table("DATAM", header = TRUE, fill = TRUE)
   
    will probably work.
   
    Best,
    Ista
   
   
    >
    >
    > Berend
    >
    >> 01.01.2001-24:00:00        12             11
    >> 01.02.2001-12:00:00        13             10
    >> 01.02.2001-24:00:00        11             12
    >> 01.03.2001-12:00:00        15             11
    >> 01.03.2001-24:00:00        16             10
    >> ...
    >>
    >> I just use the simple script to open it: df = read.table('DATAM', head=T).
    >>
    >> But it has the error and thus cannot read the file:
    >> Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
    >> dec,  :
    >>  line 1 did not have 3 elements
    >>
    >> How to read it with three fixed columns, and how to read the time format in
    >> the first column correctly? Thanks for your help.
    >>
    >>       [[alternative HTML version deleted]]
    >>
    >> ______________________________________________
    >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    >> https://stat.ethz.ch/mailman/listinfo/r-help
    >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    >> and provide commented, minimal, self-contained, reproducible code.
    >
    > ______________________________________________
    > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    > https://stat.ethz.ch/mailman/listinfo/r-help
    > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    > and provide commented, minimal, self-contained, reproducible code.
   
    ______________________________________________
    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
   

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

lily li
I use the method, df$Time = as.POSIXct(df$Time), but it has the warning
message:
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format

On Thu, Dec 14, 2017 at 1:31 PM, MacQueen, Don <[hidden email]> wrote:

> In addition to which, I would recommend
>
> df <- read.table("DATAM", header = TRUE, fill = TRUE,
> stringsAsFactors=FALSE)
>
> and then converting the Time column to POSIXct date-time values using
>   as.POSIXct()
> specifying the format using formatting codes found in
>   ?strptime
> because the times are not in the POSIXct default format.
>
>
> This example might indicate the idea:
>
> > as.POSIXct('2012-10-12 13:14')
> [1] "2012-10-12 13:14:00 PDT"
> > class(as.POSIXct('2012-10-12 13:14'))
> [1] "POSIXct" "POSIXt"
>
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 12/14/17, 11:01 AM, "R-help on behalf of Ista Zahn" <
> [hidden email] on behalf of [hidden email]> wrote:
>
>     On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]>
> wrote:
>     >
>     >> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>     >>
>     >> Hi R users,
>     >>
>     >> I have a question about reading from text files. The file has the
> structure
>     >> below:
>     >>
>     >> Time                            Column1   Column2
>     >> 01.01.2001-12:00:00
>     >
>     > This line does not contain 3 elements; only one.
>     > You'll have to fix that line. Delete it, prepend it with a comment
> character of add enough columns.
>
>     I definitely don't recommend that. Instead, read
>
>     ?read.table
>
>     to learn about the "fill" and "header" arguments.
>
>     df = read.table("DATAM", header = TRUE, fill = TRUE)
>
>     will probably work.
>
>     Best,
>     Ista
>
>
>     >
>     >
>     > Berend
>     >
>     >> 01.01.2001-24:00:00        12             11
>     >> 01.02.2001-12:00:00        13             10
>     >> 01.02.2001-24:00:00        11             12
>     >> 01.03.2001-12:00:00        15             11
>     >> 01.03.2001-24:00:00        16             10
>     >> ...
>     >>
>     >> I just use the simple script to open it: df = read.table('DATAM',
> head=T).
>     >>
>     >> But it has the error and thus cannot read the file:
>     >> Error in scan(file = file, what = what, sep = sep, quote = quote,
> dec =
>     >> dec,  :
>     >>  line 1 did not have 3 elements
>     >>
>     >> How to read it with three fixed columns, and how to read the time
> format in
>     >> the first column correctly? Thanks for your help.
>     >>
>     >>       [[alternative HTML version deleted]]
>     >>
>     >> ______________________________________________
>     >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>     >> https://stat.ethz.ch/mailman/listinfo/r-help
>     >> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
>     >> and provide commented, minimal, self-contained, reproducible code.
>     >
>     > ______________________________________________
>     > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>     > https://stat.ethz.ch/mailman/listinfo/r-help
>     > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
>     > and provide commented, minimal, self-contained, reproducible code.
>
>     ______________________________________________
>     [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

David Winsemius

> On Dec 15, 2017, at 9:21 AM, lily li <[hidden email]> wrote:
>
> I use the method, df$Time = as.POSIXct(df$Time), but it has the warning
> message:
> Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format

That's because your date-time data is not in "%Y-%m-%d %H:%M" format. Read:

 ?strptime

--
David.

>
> On Thu, Dec 14, 2017 at 1:31 PM, MacQueen, Don <[hidden email]> wrote:
>
>> In addition to which, I would recommend
>>
>> df <- read.table("DATAM", header = TRUE, fill = TRUE,
>> stringsAsFactors=FALSE)
>>
>> and then converting the Time column to POSIXct date-time values using
>>  as.POSIXct()
>> specifying the format using formatting codes found in
>>  ?strptime
>> because the times are not in the POSIXct default format.
>>
>>
>> This example might indicate the idea:
>>
>>> as.POSIXct('2012-10-12 13:14')
>> [1] "2012-10-12 13:14:00 PDT"
>>> class(as.POSIXct('2012-10-12 13:14'))
>> [1] "POSIXct" "POSIXt"
>>
>> -Don
>>
>> --
>> Don MacQueen
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>> Lab cell 925-724-7509
>>
>>
>>
>> On 12/14/17, 11:01 AM, "R-help on behalf of Ista Zahn" <
>> [hidden email] on behalf of [hidden email]> wrote:
>>
>>    On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]>
>> wrote:
>>>
>>>> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>>>>
>>>> Hi R users,
>>>>
>>>> I have a question about reading from text files. The file has the
>> structure
>>>> below:
>>>>
>>>> Time                            Column1   Column2
>>>> 01.01.2001-12:00:00
>>>
>>> This line does not contain 3 elements; only one.
>>> You'll have to fix that line. Delete it, prepend it with a comment
>> character of add enough columns.
>>
>>    I definitely don't recommend that. Instead, read
>>
>>    ?read.table
>>
>>    to learn about the "fill" and "header" arguments.
>>
>>    df = read.table("DATAM", header = TRUE, fill = TRUE)
>>
>>    will probably work.
>>
>>    Best,
>>    Ista
>>
>>
>>>
>>>
>>> Berend
>>>
>>>> 01.01.2001-24:00:00        12             11
>>>> 01.02.2001-12:00:00        13             10
>>>> 01.02.2001-24:00:00        11             12
>>>> 01.03.2001-12:00:00        15             11
>>>> 01.03.2001-24:00:00        16             10
>>>> ...
>>>>
>>>> I just use the simple script to open it: df = read.table('DATAM',
>> head=T).
>>>>
>>>> But it has the error and thus cannot read the file:
>>>> Error in scan(file = file, what = what, sep = sep, quote = quote,
>> dec =
>>>> dec,  :
>>>> line 1 did not have 3 elements
>>>>
>>>> How to read it with three fixed columns, and how to read the time
>> format in
>>>> the first column correctly? Thanks for your help.
>>>>
>>>>      [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>    ______________________________________________
>>    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>    https://stat.ethz.ch/mailman/listinfo/r-help
>>    PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>    and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Errors in reading in txt files

Jeff Newmiller
In reply to this post by lily li
Your times are formatted as

01.01.2001-24:00:00

but the default format is

2001-01-01 24:00:00

so you need to specify a format argument with as.POSIXct. Read about format strings in ?strptime.
--
Sent from my phone. Please excuse my brevity.

On December 15, 2017 9:21:54 AM PST, lily li <[hidden email]> wrote:

>I use the method, df$Time = as.POSIXct(df$Time), but it has the warning
>message:
>Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format
>
>On Thu, Dec 14, 2017 at 1:31 PM, MacQueen, Don <[hidden email]>
>wrote:
>
>> In addition to which, I would recommend
>>
>> df <- read.table("DATAM", header = TRUE, fill = TRUE,
>> stringsAsFactors=FALSE)
>>
>> and then converting the Time column to POSIXct date-time values using
>>   as.POSIXct()
>> specifying the format using formatting codes found in
>>   ?strptime
>> because the times are not in the POSIXct default format.
>>
>>
>> This example might indicate the idea:
>>
>> > as.POSIXct('2012-10-12 13:14')
>> [1] "2012-10-12 13:14:00 PDT"
>> > class(as.POSIXct('2012-10-12 13:14'))
>> [1] "POSIXct" "POSIXt"
>>
>> -Don
>>
>> --
>> Don MacQueen
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>> Lab cell 925-724-7509
>>
>>
>>
>> On 12/14/17, 11:01 AM, "R-help on behalf of Ista Zahn" <
>> [hidden email] on behalf of [hidden email]> wrote:
>>
>>     On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman <[hidden email]>
>> wrote:
>>     >
>>     >> On 14 Dec 2017, at 19:36, lily li <[hidden email]> wrote:
>>     >>
>>     >> Hi R users,
>>     >>
>>     >> I have a question about reading from text files. The file has
>the
>> structure
>>     >> below:
>>     >>
>>     >> Time                            Column1   Column2
>>     >> 01.01.2001-12:00:00
>>     >
>>     > This line does not contain 3 elements; only one.
>>     > You'll have to fix that line. Delete it, prepend it with a
>comment
>> character of add enough columns.
>>
>>     I definitely don't recommend that. Instead, read
>>
>>     ?read.table
>>
>>     to learn about the "fill" and "header" arguments.
>>
>>     df = read.table("DATAM", header = TRUE, fill = TRUE)
>>
>>     will probably work.
>>
>>     Best,
>>     Ista
>>
>>
>>     >
>>     >
>>     > Berend
>>     >
>>     >> 01.01.2001-24:00:00        12             11
>>     >> 01.02.2001-12:00:00        13             10
>>     >> 01.02.2001-24:00:00        11             12
>>     >> 01.03.2001-12:00:00        15             11
>>     >> 01.03.2001-24:00:00        16             10
>>     >> ...
>>     >>
>>     >> I just use the simple script to open it: df =
>read.table('DATAM',
>> head=T).
>>     >>
>>     >> But it has the error and thus cannot read the file:
>>     >> Error in scan(file = file, what = what, sep = sep, quote =
>quote,
>> dec =
>>     >> dec,  :
>>     >>  line 1 did not have 3 elements
>>     >>
>>     >> How to read it with three fixed columns, and how to read the
>time
>> format in
>>     >> the first column correctly? Thanks for your help.
>>     >>
>>     >>       [[alternative HTML version deleted]]
>>     >>
>>     >> ______________________________________________
>>     >> [hidden email] mailing list -- To UNSUBSCRIBE and more,
>see
>>     >> https://stat.ethz.ch/mailman/listinfo/r-help
>>     >> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>     >> and provide commented, minimal, self-contained, reproducible
>code.
>>     >
>>     > ______________________________________________
>>     > [hidden email] mailing list -- To UNSUBSCRIBE and more,
>see
>>     > https://stat.ethz.ch/mailman/listinfo/r-help
>>     > PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>     > and provide commented, minimal, self-contained, reproducible
>code.
>>
>>     ______________________________________________
>>     [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>     https://stat.ethz.ch/mailman/listinfo/r-help
>>     PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>     and provide commented, minimal, self-contained, reproducible
>code.
>>
>>
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.