[R] can not read a table

Petr PIKAL petr.pikal at precheza.cz
Wed Jun 20 18:14:41 CEST 2012


Hi

> 
> 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)

I would read the file by readLines, get rid of lines containing "Table" 
and "ID" strings, and split the values to 2 columns
Probably not the best approach but something like

test<-readLines("clipboard")
test<-test[-grep("TABLE", test)]
test<-test[-grep("ID", test)]
t(sapply(strsplit(test, "\t\t"), as.numeric))
     [,1] [,2]
[1,] 1325    0
[2,] 1325    0
[3,] 1325    0
[4,] 1325    0

can work
You can transfer it to data frame easily.

Regards
Petr


> 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 at r-project.org 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.



More information about the R-help mailing list