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]]
y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1)) colnames(y) <- gsub("X","", colnames(y)) Use read.table's check.names=FALSE argument so it won't mangle the column names instead of trying to demangle them with gsub() afterwards. E.g., txt <- " 50% 100%\nA 5 8\nB 13 14\n" cat(txt) # 50% 100% #A 5 8 #B 13 14 read.table(text=txt, head=TRUE, row.names=1) # X50. X100. #A 5 8 #B 13 14 read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE) # 50% 100% #A 5 8 #B 13 14 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa <tanasa at gmail.com> wrote:> 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]] > > ______________________________________________ > 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]]
dear William , I have an issue with R code which is : FCP<-as.matrix(sapply(FCPval,as.numeric)) for (i in 1:rowN){if (FCP$FC[i] >= 1.5 & FCP$FC[i]<=-1.5 & FCP$p[i]<=0.05){ dfrmPFC=data.frame(matrix(Fc=FC,p=p))} } the error is :Error in FCP$FC : $ operator is invalid for atomic vectors could you please help me On Thu, Sep 3, 2015 at 12:32 AM, William Dunlap [via R] < ml-node+s789695n4711779h48 at n4.nabble.com> wrote:> y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1)) > colnames(y) <- gsub("X","", colnames(y)) > > Use read.table's check.names=FALSE argument so it won't mangle > the column names instead of trying to demangle them with gsub() > afterwards. > > E.g., > txt <- " 50% 100%\nA 5 8\nB 13 14\n" > cat(txt) > # 50% 100% > #A 5 8 > #B 13 14 > read.table(text=txt, head=TRUE, row.names=1) > # X50. X100. > #A 5 8 > #B 13 14 > read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE) > # 50% 100% > #A 5 8 > #B 13 14 > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=4711779&i=0>> wrote: > > > 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 <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=4711779&i=1>> > > 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 <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=4711779&i=2>> 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=4711779&i=3> 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]] > > > > ______________________________________________ > > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711779&i=4> > 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]] > > ______________________________________________ > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711779&i=5> > 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-tp4711774p4711779.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-tp4711774p4711780.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
that is great, thank you Bill for time and help ;) ! On Wed, Sep 2, 2015 at 4:36 PM, William Dunlap <wdunlap at tibco.com> wrote:> y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1)) > colnames(y) <- gsub("X","", colnames(y)) > > Use read.table's check.names=FALSE argument so it won't mangle > the column names instead of trying to demangle them with gsub() > afterwards. > > E.g., > txt <- " 50% 100%\nA 5 8\nB 13 14\n" > cat(txt) > # 50% 100% > #A 5 8 > #B 13 14 > read.table(text=txt, head=TRUE, row.names=1) > # X50. X100. > #A 5 8 > #B 13 14 > read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE) > # 50% 100% > #A 5 8 > #B 13 14 > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa <tanasa at gmail.com> wrote: > >> 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]] >> >> ______________________________________________ >> 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]]