[R] can not read a table

Sarah Goslee sarah.goslee at gmail.com
Wed Jun 20 19:55:01 CEST 2012


On Wed, Jun 20, 2012 at 12:51 PM, york8866 <yu_york at hotmail.com> wrote:
> it seems it will work, however, the last line of code did not work, so I can
> not check the results.
> thanks,

What does "did not work" mean?

Your computer exploded?
R evaporated?
Your file vanished?
It gave an error message that you did not provide us?
It did not give an error message, but the result was not what you
expected, and you didn't provide it to us?

We still haven't come up with the telepathy package. Please do tell us
what happens.

> jholtman wrote
>>
>> try this by reformatting the data and then reading back in:
>>
>>
>>> x <- readLines(textConnection("TABLE NO.  1
>> + ID      TIME
>> + 1325    0
>> + 1325    0
>> + TABLE NO.  1
>> + ID      TIME
>> + 1325    0
>> + 1325    0
>> + TABLE NO.  1
>> + ID      TIME
>> + 1325    0
>> + 1325    0
>> + TABLE NO.  1
>> + ID      TIME
>> + 1325    0
>> + 1325    0"))
>>>
>>> # remove "TABLE"
>>> x <- x[-grep("^TABLE", x)]
>>>
>>> # remove all but first "ID"
>>> x <- x[-grep("^ID", x)[-1]]
>>>
>>> # now create temporary file with the data to re-read
>>> fileName <- tempfile()
>>> writeLines(x, fileName)
>>>
>>> # now read in the data
>> />* read.table(fileName, header = TRUE)*/
>>
>> ID TIME
>> 1 1325    0
>> 2 1325    0
>> 3 1325    0
>> 4 1325    0
>> 5 1325    0
>> 6 1325    0
>> 7 1325    0
>> 8 1325    0
>>>
>>>
>>
>>
>> On Wed, Jun 20, 2012 at 10:08 AM, york8866 <yu_york@> wrote:
>>> I have a table like the following:
>>>
>>> TABLE NO.  1
>>> ID      TIME
>>> 1325    0
>>> 1325    0
>>> .       .
>>> .       .
>>> .       .
>>> TABLE NO.  1
>>> ID      TIME
>>> 1325    0
>>> 1325    0
>>> .       .
>>> .       .
>>> .       .
>>> TABLE NO.  1
>>> ID      TIME
>>> 1325    0
>>> 1325    0
>>> .       .
>>> .       .
>>> .       .
>>> TABLE NO.  1
>>> ID      TIME
>>> 1325    0
>>> 1325    0
>>> .       .
>>> .       .
>>> .       .
>>>
>>> I used the following code:
>>> sim <- read.table("sim.tab", skip=1, as.is=T,header=T)
>>> it did not work, as there're rows with characters in between the data.
>>> Can anyone help me to read the table, while get rid of the character rows
>>> in
>>> between the data?
>>> thanks,
>>>
>>> --

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list