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"