Search code examples
rstringsubstringbioconductor

How to subset String object in R


I have an AAString () object like below, how can I subset for multiple positions?

df <- AAString("HAKTKIDLTBI")
df

11-letter AAString object
seq: HAKTKIDLTBI

I want to subset for :

substring(df,c(1,3,4,10))

Output:

seq: HKTB

Solution

  • You can use standard indices

    df <- AAString("HAKTKIDLTBI")
    df[c(1,3,4,10)]
    ##  4-letter AAString object
    ##  seq: HKTB