barcode = c("Case-001-B", "Control-001-A", "Case-002-A", "001")
subsetString(barcode, sep="-", position=2, flexible=TRUE)
subsetString(barcode, sep="-", position=3, flexible=TRUE)
subsetString(barcode, sep="-", position=3, flexible=FALSE)
Run the code above in your browser using DataLab