Dear all, would appreciate a piece of help with a simple question: I am reading in R a file that is formatted as a matrix (an example is shown below, although it is more complex, a matrix of 1000 * 1000 ): the names of the columns are 0, 10000, 40000, 80000, etc the names of the rows are 0, 10000, 40000, 80000, etc 0 200000 400000 0 0 0 0 200000 0 0 0 400000 0 0 0 shall I use the command : y <- read.table("file",row.names=1, header=T) the results is :> y[1:3,1:3]X0 X200000 X400000 0 0 0 0 200000 0 0 0 400000 0 0 0 The question is : why R adds an X to the names of the columns eg X0, X20000, X40000, when it shall be only 0, 20000, 40000 ? thanks ! -- bogdan [[alternative HTML version deleted]]
also the header =0 On Wed, Sep 2, 2015 at 11:52 PM, Shawin Karim <shawinkarim at gmail.com> wrote:> make row.name=0 instead to 1 > > On Wed, Sep 2, 2015 at 11:07 PM, Bogdan Tanasa [via R] < > ml-node+s789695n4711774h93 at n4.nabble.com> wrote: > >> Dear all, >> >> would appreciate a piece of help with a simple question: I am reading in >> R >> a file that is formatted as a matrix (an example is shown below, although >> it is more complex, a matrix of 1000 * 1000 ): >> >> the names of the columns are 0, 10000, 40000, 80000, etc >> the names of the rows are 0, 10000, 40000, 80000, etc >> >> 0 200000 400000 >> 0 0 0 0 >> 200000 0 0 0 >> 400000 0 0 0 >> >> shall I use the command : >> >> y <- read.table("file",row.names=1, header=T) >> >> the results is : >> >> > y[1:3,1:3] >> X0 X200000 X400000 >> 0 0 0 0 >> 200000 0 0 0 >> 400000 0 0 0 >> >> The question is : why R adds an X to the names of the columns eg X0, >> X20000, X40000, when it shall be only 0, 20000, 40000 ? thanks ! >> >> -- bogdan >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711774&i=0> >> mailing list -- To UNSUBSCRIBE and more, see >> 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. >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://r.789695.n4.nabble.com/reading-files-with-name-columns-and-row-columns-tp4711774.html >> To start a new topic under R help, email >> ml-node+s789695n789696h75 at n4.nabble.com >> To unsubscribe from R, click here >> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=789695&code=c2hhd2lua2FyaW1AZ21haWwuY29tfDc4OTY5NXwtMjQ0MzkwMjQ1> >> . >> NAML >> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > >-- View this message in context: http://r.789695.n4.nabble.com/reading-files-with-name-columns-and-row-columns-tp4711774p4711776.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Please read the Help file carefully before posting: "read.table is not the right tool for reading large matrices, especially those with many columns: it is designed to read data frames which may have columns of very different classes. Use scan instead for matrices." But the answer to your question can be found in ?make.names for what constitutes a syntactically valid name in R. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa <tanasa at gmail.com> wrote:> Dear all, > > would appreciate a piece of help with a simple question: I am reading in R > a file that is formatted as a matrix (an example is shown below, although > it is more complex, a matrix of 1000 * 1000 ): > > the names of the columns are 0, 10000, 40000, 80000, etc > the names of the rows are 0, 10000, 40000, 80000, etc > > 0 200000 400000 > 0 0 0 0 > 200000 0 0 0 > 400000 0 0 0 > > shall I use the command : > > y <- read.table("file",row.names=1, header=T) > > the results is : > >> y[1:3,1:3] > X0 X200000 X400000 > 0 0 0 0 > 200000 0 0 0 > 400000 0 0 0 > > The question is : why R adds an X to the names of the columns eg X0, > X20000, X40000, when it shall be only 0, 20000, 40000 ? thanks ! > > -- bogdan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Thanks, Bert ! I solved the situation in the meanwhile, by using : y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1)) colnames(y) <- gsub("X","", colnames(y)) On Wed, Sep 2, 2015 at 3:59 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> Please read the Help file carefully before posting: > > "read.table is not the right tool for reading large matrices, > especially those with many columns: it is designed to read data frames > which may have columns of very different classes. Use scan instead for > matrices." > > But the answer to your question can be found in > > ?make.names > > for what constitutes a syntactically valid name in R. > > > Cheers, > Bert > > Bert Gunter > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." > -- Clifford Stoll > > > On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa <tanasa at gmail.com> wrote: > > Dear all, > > > > would appreciate a piece of help with a simple question: I am reading in > R > > a file that is formatted as a matrix (an example is shown below, although > > it is more complex, a matrix of 1000 * 1000 ): > > > > the names of the columns are 0, 10000, 40000, 80000, etc > > the names of the rows are 0, 10000, 40000, 80000, etc > > > > 0 200000 400000 > > 0 0 0 0 > > 200000 0 0 0 > > 400000 0 0 0 > > > > shall I use the command : > > > > y <- read.table("file",row.names=1, header=T) > > > > the results is : > > > >> y[1:3,1:3] > > X0 X200000 X400000 > > 0 0 0 0 > > 200000 0 0 0 > > 400000 0 0 0 > > > > The question is : why R adds an X to the names of the columns eg X0, > > X20000, X40000, when it shall be only 0, 20000, 40000 ? thanks ! > > > > -- bogdan > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. >[[alternative HTML version deleted]]