[R] Read text file

arun smartpink111 at yahoo.com
Tue Mar 11 13:40:17 CET 2014


Hi,
There is no GPGLL or GPGLA entries in the data.  You can use ?grep to read those lines.
##Modifying the input data
lines1 <- readLines(textConnection("1377262633.948000    $GPRMC,125708.00,A,5047.66107,N,00603.65528,E,0.203,247.36,230813,,,A*60
1377262633.958000    $GPVTG,247.36,T,,M,0.203,N,0.377,K,A*3B
1377262633.968000    $GPGLA,125708.00,5047.66107,N,00603.65528,E,1,09,0.85,169.3,M,46.5,M,,*52
1377262633.978000    $GPGSA,A,3,29,21,31,25,16,05,06,13,27,,,,1.78,0.85,1.57*0C
1377262633.998000    $GPGSV,3,1,12,03,01,266,,05,16,043,39,06,21,263,43,13,07,330,43*70
1377262634.008000    $GPGLL,3,2,12,16,37,302,45,18,03,149,,21,59,166,33,23,04,304,16*75
1377262634.028000    $GPGSV,3,3,12,25,18,129,21,27,11,260,39,29,45,071,47,31,35,211,47*7C")) 

dat <- read.table(text=lines1[grepl("GPGLA|GPGLL",lines1)],header=FALSE,stringsAsFactors=FALSE,sep=",",fill=TRUE)
A.K.




On Tuesday, March 11, 2014 8:02 AM, Alaios <alaios at yahoo.com> wrote:
Hi all
I am trying to read some text files with the following format:

1377262633.948000    $GPRMC,125708.00,A,5047.66107,N,00603.65528,E,0.203,247.36,230813,,,A*60
1377262633.958000    $GPVTG,247.36,T,,M,0.203,N,0.377,K,A*3B
1377262633.968000    $GPGGA,125708.00,5047.66107,N,00603.65528,E,1,09,0.85,169.3,M,46.5,M,,*52
1377262633.978000    $GPGSA,A,3,29,21,31,25,16,05,06,13,27,,,,1.78,0.85,1.57*0C
1377262633.998000    $GPGSV,3,1,12,03,01,266,,05,16,043,39,06,21,263,43,13,07,330,43*70
1377262634.008000    $GPGSV,3,2,12,16,37,302,45,18,03,149,,21,59,166,33,23,04,304,16*75
1377262634.028000    $GPGSV,3,3,12,25,18,129,21,27,11,260,39,29,45,071,47,31,35,211,47*7C

but this returns me the following:

read.csv("sensor_0.log",sep=",")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  more columns than column names

I guess the problem is that the columns are not consistent on a per row basis.
What  I am trying to do though is to read only the lines that contain the $GPGLL or the $GPGLA entries (in the example they corresponds to 3rd and 4th line).
How can I do this in R?

Regards
A
    [[alternative HTML version deleted]]

______________________________________________
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