[R] can not read a table
york8866
yu_york at hotmail.com
Wed Jun 20 18:51:46 CEST 2012
it seems it will work, however, the last line of code did not work, so I can
not check the results.
thanks,
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,
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/can-not-read-a-table-tp4633971.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help@ mailing list
>> 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.
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> ______________________________________________
> R-help@ mailing list
> 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.
>
--
View this message in context: http://r.789695.n4.nabble.com/can-not-read-a-table-tp4633971p4633994.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list