Hi, I am new to R and need to read in a file with 19 columns and 7000 rows and make it into a list of 7000 lists with 19 items each. For a simpler case of 10 by 10 table I used x <-scan("file", list(0,0,0,0,0,0,0,0,0,0)), perhaps clumsy, but it did the job. However with the large 19x7000 (which needs to be transposed) I am not sure how to go about it. Coudl somebody suggest a way? Thanks, Tomas
On Sat, 20 Oct 2007, Tomas Vaisar wrote:> Hi, > > I am new to R and need to read in a file with 19 columns and 7000 rows > and make it into a list of 7000 lists with 19 items each. For a > simpler case of 10 by 10 table I used x <-scan("file", > list(0,0,0,0,0,0,0,0,0,0)), perhaps clumsy, but it did the job. > However with the large 19x7000 (which needs to be transposed) I am not > sure how to go about it. > > Coudl somebody suggest a way?dat <- as.data.frame( matrix( scan('tmp.txt'), nr=19) ) returns a data.frame which is a list with some added attributes. or dat <- lapply( readLines('tmp.txt'), function(x) scan(textConnection(x) ) ) Or char.dat <- strsplit( readLines('tmp.txt'), split='[[:blank:]]+') numeric.dat <- lapply( char.dat, as.numeric ) HTH, Chuck> > Thanks, > > Tomas > > ______________________________________________ > 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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
another choice is: x <- scan('temp.txt', what=c(rep(list(0), 19))) On 10/20/07, Tomas Vaisar <tvaisar at u.washington.edu> wrote:> Hi, > > I am new to R and need to read in a file with 19 columns and 7000 rows > and make it into a list of 7000 lists with 19 items each. For a > simpler case of 10 by 10 table I used x <-scan("file", > list(0,0,0,0,0,0,0,0,0,0)), perhaps clumsy, but it did the job. > However with the large 19x7000 (which needs to be transposed) I am not > sure how to go about it. > > Coudl somebody suggest a way? > > Thanks, > > Tomas > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?