I am trying to read a file with 8 columns and about 200 rows into a matrix. I tried something like: x<-matrix(data="data.txt", nrow=200, ncol=8) but this produces a matrix with "data.txt" in it. Is there a way to read the data in? Any pointers in the right direction would be appreciated. Thank you!
Sundar Dorai-Raj
2004-Aug-26 16:18 UTC
[R] newbie question: how to read a file into a matrix
Gaby Aguilera wrote:> I am trying to read a file with 8 columns and about 200 rows into a > matrix. I tried something like: > x<-matrix(data="data.txt", nrow=200, ncol=8) but this produces a > matrix with "data.txt" in it. Is there a way to read the data in? > > Any pointers in the right direction would be appreciated. Thank you! >You should read "R Data Import/Export" (and the posting guide). http://cran.r-project.org/doc/manuals/R-data.pdf What you are looking for is ?read.table or ?scan. Also read ?matrix while you are at it. x <- matrix(scan("data.txt"), nrow = 200, ncol = 8) --sundar
Hi, -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [SMTP:r-help-bounces at stat.math.ethz.ch] On Behalf Of Gaby Aguilera Sent: Thursday, August 26, 2004 5:47 PM To: r-help at stat.math.ethz.ch Subject: [R] newbie question: how to read a file into a matrix> matrix with "data.txt" in it. Is there a way to read the data in? > > Any pointers in the right direction would be appreciated. Thank you! >The pointer in the right direction is the bottom of each message: read the posting guide. And there it says you should at least read the relevant section in "An Introduction to R" which is shipped with every distribution of R. So please read section 7 there. What you probably want to do is: ### assuming you are working on Windows x <- read.table("c:\\mydatafolder\\data.txt", sep=",", header=TRUE) # depending on your separator and whether you have variable names For some more information you may also check the "R Data Import/Export Manual" also included in every distribution of R. Best, Roland +++++ This mail has been sent through the MPI for Demographic Rese...{{dropped}}
Arne Henningsen
2004-Aug-26 16:28 UTC
[R] newbie question: how to read a file into a matrix
Please read the "R Data Import/Export" manual. It should be on your harddisk and it is also available from http://cran.r-project.org/doc/manuals/R-data.pdf Arne On Thursday 26 August 2004 17:47, Gaby Aguilera wrote:> I am trying to read a file with 8 columns and about 200 rows into a > matrix. I tried something like: > x<-matrix(data="data.txt", nrow=200, ncol=8) but this produces a > matrix with "data.txt" in it. Is there a way to read the data in? > > Any pointers in the right direction would be appreciated. Thank you! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html-- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de http://www.uni-kiel.de/agrarpol/ahenningsen/
Ernesto Jardim
2004-Aug-26 16:31 UTC
[R] newbie question: how to read a file into a matrix
On Thu, 2004-08-26 at 16:47, Gaby Aguilera wrote:> I am trying to read a file with 8 columns and about 200 rows into a > matrix. I tried something like: > x<-matrix(data="data.txt", nrow=200, ncol=8) but this produces a > matrix with "data.txt" in it. Is there a way to read the data in? > > Any pointers in the right direction would be appreciated. Thank you! >Hi, Read the R manuals ... and use function "read.table" or similar. EJ
asemeria@cramont.it
2004-Aug-26 16:42 UTC
[R] newbie question: how to read a file into a matrix
I think was better you read something on "R data Import/Export" (base documentation available for all R distribution). A.S. ---------------------------- Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: alessandro.semeria at cramont.it