Home > Software engineering >  Selecting specific length of characters in a dataset
Selecting specific length of characters in a dataset

Time:11-16

I have a proteomics dataset with a list of peptides. e.g.

x = c("DFGVEVDNNSYK","EFHIR","VGQEYQPR","AYQVEGDWSGAAFMLVAGAIAGSIEVENLNTR","SHQADR","AILDALK","LR").

I want to extract a list peptides where the peptide length is between 4-10. How can I do this with

nchar?

CodePudding user response:

Use the nchar() function:

x <- c("DFGVEVDNNSYK", "EFHIR", "VGQEYQPR", "AYQVEGDWSGAAFMLVAGAIAGSIEVENLNTR", "SHQADR", "AILDALK", "LR")
output <- x[nchar(x) >= 4 & nchar(x) <= 10]
output

[1] "EFHIR"    "VGQEYQPR" "SHQADR"   "AILDALK"
  •  Tags:  
  • r
  • Related