Hello, I'am new to the R world and have a lot of question but the first is : How to deal with <> opertor in table objects? (Or how to deal with <> in general...) I explain my problem. I read a file with the read.table expression. I then obtain a matrix. I read the first line for example with the commande data[,1]. Then I would like to select only the element in this line that are greater than 2. Is there an elegant way to achieve that ? Thanks by advance... -- View this message in context: http://www.nabble.com/Operator-%3E-and-%3C-tf4141869.html#a11781567 Sent from the R help mailing list archive at Nabble.com.
Yann Mauon wrote:> Hello, > > I'am new to the R world and have a lot of question but the first is : How to > deal with <> opertor in table objects? (Or how to deal with <> in > general...) I explain my problem. > > I read a file with the read.table expression. I then obtain a matrix. I read > the first line for example with the commande data[,1]. Then I would like to > select only the element in this line that are greater than 2. Is there an > elegant way to achieve that ? > > Thanks by advance...Note that read.table() returns a data frame, not a matrix. To subset, try this: subset(data, data[,1] > 2) OR subset(data, data[,1] > 2, select=1) Of course, it is always nice if each column in your data frame has a meaningful name, so it can be referred to by name rather than number. ?subset ?names -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
mm <- matrix(1:9, nrow=3) ; mm subset(mm[,1],mm[,1] <3) # Note I used 3 not 2 here. Have a look at some of the introductory documents on the R site ( Contributed documents under OTHER in the documentation). They should answer a lot of your basic questions like this. Documents by Lemon, Maindonald and Verzani are good places to start. Also the Introduction to R is useful. --- Yann Mauon <yann.mauron at genebio.com> wrote:> > Hello, > > I'am new to the R world and have a lot of question > but the first is : How to > deal with <> opertor in table objects? (Or how to > deal with <> in > general...) I explain my problem. > > I read a file with the read.table expression. I then > obtain a matrix. I read > the first line for example with the commande > data[,1]. Then I would like to > select only the element in this line that are > greater than 2. Is there an > elegant way to achieve that ? > > Thanks by advance... > -- > View this message in context: >http://www.nabble.com/Operator-%3E-and-%3C-tf4141869.html#a11781567> Sent from the R help mailing list archive at > Nabble.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. >
Hi you definitely shall make a quick glance to some documentation which comes with R e.g. R intro manual. Or look at CRAN where is quite impressive amount of literature from basic stuff to advanced papers. To your question: r-help-bounces at stat.math.ethz.ch napsal dne 25.07.2007 14:23:58:> > Hello, > > I'am new to the R world and have a lot of question but the first is :How to> deal with <> opertor in table objects? (Or how to deal with <> in > general...) I explain my problem. > > I read a file with the read.table expression. I then obtain a matrix. Iread> the first line for example with the commande data[,1]. Then I would liketo You did not select line but column. data[,1] > 2 will give you logical vector which you can use for selection of rows from data. data[data[,1] > 2,] Regards. Petr> select only the element in this line that are greater than 2. Is therean> elegant way to achieve that ? > > Thanks by advance... > -- > View this message in context:http://www.nabble.com/Operator-%3E-and-%3C-> tf4141869.html#a11781567 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.