Hi All, Sorry for this basic question as I am new to this R. I would like to know, is it possible to consider a matrix with some columns having numeric data and some other's with characters (strings) data? How do I get this type of data from a flat file. Thanks very much, mallika ____________________________________________________________________________ Mallika Veeramalai, Ph.D., Postdoctoral Associate, Bioinformatics & Systems Biology, Burnham Institute for Medical Research, La Jolla, CA 92037, USA. phone : +1 858 646 3100 ext: 3627 Fax : +1 858 795 5249 Web : http://bioinformatics.burnham.org/~mallika/ Email : mallikav at burnham.org (or) kaaviyam at gmail.com
Mallika Veeramalai <mallikav <at> burnham.org> writes: I would like to know,> is it possible to consider a matrix with some columns having numeric data > and some other's with characters (strings) data? How do I get this type of > data from a flat file.It's called a "data frame". See the Introduction to R, and help for read.table and read.csv. (The character data will get made into factors unless you use as.is=TRUE or specify colClasses.)
--- Mallika Veeramalai <mallikav at burnham.org> wrote:> > Hi All, > > Sorry for this basic question as I am new to this R. > I would like to know, > is it possible to consider a matrix with some > columns having numeric data > and some other's with characters (strings) data? > How do I get this type of > data from a flat file. > > Thanks very much, > mallikaIf I understand the question the answer is NO. A matrix must be of one type of data. I think that what you want is a data.frame wich allows mixed categores of data. Try this to see the difference. a <- c('a','b','c') b <- c( 1,2,3) aa <- cbind(a,b) aa class(aa) bb <- data.frame(a,b) bb class(bb)
See ?data.frame ?read.table and please read (appropriate parts of) the "Introduction to R" manual. Petr Mallika Veeramalai napsal(a):> Hi All, > > Sorry for this basic question as I am new to this R. I would like to know, > is it possible to consider a matrix with some columns having numeric data > and some other's with characters (strings) data? How do I get this type of > data from a flat file. > > Thanks very much, > mallika > > ____________________________________________________________________________ > Mallika Veeramalai, Ph.D., > Postdoctoral Associate, > Bioinformatics & Systems Biology, > Burnham Institute for Medical Research, > La Jolla, CA 92037, USA. > phone : +1 858 646 3100 ext: 3627 > Fax : +1 858 795 5249 > Web : http://bioinformatics.burnham.org/~mallika/ > Email : mallikav at burnham.org (or) kaaviyam at gmail.com > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
A matrix can only have 1 type of data, so if you try to include both strings and numbers in a matrix, the numbers will be converted to strings. Another type of data object is a data frame, a data frame works much like a matrix in many ways, but allows some columns to be numbers and others to be strings (though usually strings are converted to factors). You should read (or reread) the help page "An Introduction to R", section 5 talks about matricies, then section 6 talks about data frames (and lists). Section 7 shows how to read data from files into data frames. Those 3 sections should answer your questions below. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Mallika Veeramalai > Sent: Friday, March 09, 2007 1:03 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Reg. strings and numeric data in matrix. > > > Hi All, > > Sorry for this basic question as I am new to this R. I would > like to know, is it possible to consider a matrix with some > columns having numeric data and some other's with characters > (strings) data? How do I get this type of data from a flat file. > > Thanks very much, > mallika > > ______________________________________________________________ > ______________ > Mallika Veeramalai, Ph.D., > Postdoctoral Associate, > Bioinformatics & Systems Biology, > Burnham Institute for Medical Research, > La Jolla, CA 92037, USA. > phone : +1 858 646 3100 ext: 3627 > Fax : +1 858 795 5249 > Web : http://bioinformatics.burnham.org/~mallika/ > Email : mallikav at burnham.org (or) kaaviyam at gmail.com > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >