1

Hello please find below mentioned code. What I want is to add values to my array on the basis of certain condition checks which I want to undertake. If the values are eligible, then they should add to array otherwise they should be discarded. However, I am unable to get the required array. Any help in that regard will be of great help.

>NODE_1
[1]GTTGGCCGAGCCCCAGGACGCGTGGTTGTTGAACCAGATCAGGTCCGGGCTCCACTGCACGTAGTCCTCTTCCCAATTTCCCTTAA

>NODE_2
[1] CCTCCGGCGGCACCACGGTCGGCGAGGCCCTCAACATCCTG GAGCGCACCGACCTGTCCACCGCGGACAAGGCCGGTTACCT
GCACCGCTACATCGAGGCCAGCCGCATCGCGTTCGCGGACC 

>NODE_3
[1]GCCCGGCGCCTGGCCGCGGGCGAGTGGGTCGTGGACCTGCGCTCCCGGGTGGCCTTCGCCGCCGGTCACGTCGCCGGG
   TCGCTCAACTTCGAGGCCGACGGACAGCT

My code is:

Length <- function(a)
{
  b<-list()
  for ( i in 1: length(a))
  {
    b[i]<-which(length(a[i])<30, arr.ind = FALSE, useNames = TRUE)
    m<- array(b[i])
  }
}
k<- Length(Y)

So what I want to do is add only those data to array b from Y whose length is less than 30.

Thomas
  • 43,637
  • 12
  • 109
  • 140
sagar
  • 65
  • 1
  • 1
  • 4
  • You need to reformat this question: one of the ">" symbols is causing the data to be displayed incorrectly as a blockquote. – neilfws Aug 05 '11 at 09:41
  • 1
    @Ankur: You have asked at least four an maybe more questions about similar data. At no time have your effectively clarified what its structure is. You have not heeded the message that one was closed because the question was too obscure to be answered. YOU NEED TO USE THE dput() function to post your data. Typing ">NODE_1 makes us think there are single objects named NODE_1, NODE_2, NODE_3. Looping methods would need to use get() in order to process such an ineffective data arrangement. – IRTFM Aug 05 '11 at 14:28
  • The thing is that I can't use Bioconductor , I have to do it in basic R. But I am very thankful to all of you. @Ankur – sagar Aug 07 '11 at 09:55
  • possible duplicate of [How to input Array in R](http://stackoverflow.com/questions/6947146/how-to-input-array-in-r) – joran Aug 26 '11 at 15:26

1 Answers1

1

you should use nchar() instead of length() to get the number of characters.

And to do it the R way, you could use the boolean index: k <- a[nchar(a)<30]

Hope that helps!

Anatoliy
  • 1,350
  • 9
  • 9