Re: [R] Reading mixed tables

From: Hesen Peng <hesen.peng_at_gmail.com>
Date: Sat, 29 Nov 2008 20:39:16 -0500

Yes. I'm just for killing time in the rainy weekend. Now I'm using readLines() to read the file and then output the data as a list.

google.read.list <- function(filename){
  temp <- readLines(filename)
  out <- NULL
  tt <- NULL
  for(i in 1:length(temp)){
    strin <- as.numeric(strsplit(temp[i]," ")[[1]])     if(length(strin)==3){
      tt <- rbind(tt,strin)
    }else{

      if(!is.null(tt)){
        out <- c(out,list(tt))
      }
      tt <- NULL

    }
  }
  return(out)
}

On Sat, Nov 29, 2008 at 8:13 PM, David Winsemius <dwinsemius_at_comcast.net> wrote:
> Have you looked at the documentation and help files for R Import/Export;
>
> http://cran.r-project.org/doc/manuals/R-data.pdf
>
> and the read functions
>
> ?read.table
> ?readLines
> ?count.fields
>
> This is pretty basic stuff. After an extremely cursory look at that problem
> I was guessing that it is more like linear programming than statistics.
>
> --
> David Winsemius
>
>
> On Nov 29, 2008, at 6:51 PM, Hesen Peng wrote:
>
>> Dear R buddies,
>>
>> This weekend I became interested in solving Google Code Jam problems
>> using R. I guess R may work very well in this kind of contests but the
>> input of file has been a problem for me. Take this case for example
>>
>> (http://code.google.com/codejam/contest/dashboard?c=agdjb2RlamFtchALEghjb250ZXN0cxjRzBQM),
>> the files are usually of the form:
>>
>> A(number of lines for group 1)
>> a11 a12 a13
>> a21 a22 a23
>> ...
>> B(number of lines for group 2)
>> b11 b12 b13
>> b21 b22 b23
>> ...
>>
>> I guess SAS may work pretty well in this kind of situation with data
>> step. But I don't know how to handle them using R. Any suggestions?
>> Thanks a lot.
>>
>> Best wishes,
>> --
>> 彭河森 Hesen Peng
>> http://hesen.peng.googlepages.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.
>
>

-- 
彭河森 Hesen Peng
http://hesen.peng.googlepages.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.
Received on Sun 30 Nov 2008 - 01:42:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Nov 2008 - 02:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive