Search code examples
rstringsplitsubstr

Trying to return a specified number of characters from a gene sequence in R


I have a DNA sequence like: cgtcgctgtttgtcaaagtcg....

that is possibly 1000+ letters long.

However, I only want to look at letters 5 to 200, for example, and to define this subset of the string as a new object.

I tried looking at the nchar function, but haven't found something that would do this.


Solution

  • Try

    substr("cgtcgctgtttgtcaa[...]", 5, 200)
    

    See substr().