Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting specific length of characters in a dataset

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading