Hi, I was wondering if anybody can help me. In the small data set below I would like to select the index which doesn't contain the letter 'N' in the variable 'letters'. How can I discard these rows when the letter has a different position everytime (but the same letter for the whole column)? index<-c(1,2,3) letters<-c("CCTTGGAA", "NNTTGGAAT", "AACCTTNN") z<-data.frame(index,letters) index letters 1 1 CCTTGGAA 2 2 NNTTGGAAT 3 3 AACCTTNN Thanks in advance! Naomi
one way is: index <- c(1, 2, 3) let <- c("CCTTGGAA", "NNTTGGAAT", "AACCTTNN") z <- data.frame(index, let) index[-grep("N", let)] # or z[-grep("N", let), ] I hope it helps. Best, Dimitris naomi.duijvesteijn at ipg.nl wrote:> Hi, > > I was wondering if anybody can help me. In the small data set below I would like to select the index which doesn't contain the letter 'N' in the variable 'letters'. How can I discard these rows when the letter has a different position everytime (but the same letter for the whole column)? > > index<-c(1,2,3) > letters<-c("CCTTGGAA", "NNTTGGAAT", "AACCTTNN") > z<-data.frame(index,letters) > > > index letters > 1 1 CCTTGGAA > 2 2 NNTTGGAAT > 3 3 AACCTTNN > > > Thanks in advance! > Naomi > > ______________________________________________ > R-help at r-project.org 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
You really should not assign a new value to "letters" since it is a very useful constant vector that allows working with lowercase letters. Notice that Domitris did not copy your code exactly. Next time you start R type letters at the R prompt. You cannot do so now, since you overwrote that constant with your own construction. LETTERS would still work. -- David Winsemius On Feb 13, 2009, at 10:18 AM, naomi.duijvesteijn at ipg.nl wrote:> Hi, > > I was wondering if anybody can help me. In the small data set below > I would like to select the index which doesn't contain the letter > 'N' in the variable 'letters'. How can I discard these rows when the > letter has a different position everytime (but the same letter for > the whole column)? > > index<-c(1,2,3) > letters<-c("CCTTGGAA", "NNTTGGAAT", "AACCTTNN") > z<-data.frame(index,letters) > > > index letters > 1 1 CCTTGGAA > 2 2 NNTTGGAAT > 3 3 AACCTTNN > > > Thanks in advance! > Naomi > > ______________________________________________ > R-help at r-project.org 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.