r - Get specific part of a string for each line -
i have data want take specific part of
doseresponse_curves/drcurve_aaatt.pdf doseresponse_curves/drcurve_agmk1.pdf doseresponse_curves/drcurve_agu.pdf doseresponse_curves/drcurve_alh1l2.pdf doseresponse_curves/drcurve_alkb1.pdf doseresponse_curves/drcurve_as2.pdf doseresponse_curves/drcurve_ank1.pdf doseresponse_curves/drcurve_ankrd54.pdf
i want take whatever comes after second _ , before . means output looks this
aaatt agmk1 agu alh1l2 alkb1 as2 ank1 ankrd54
note: working gene names, can contain characters such c(".", "-")
.
you can sub , regular expression.
files = c( 'doseresponse_curves/drcurve_aaatt.pdf', 'doseresponse_curves/drcurve_agmk1.pdf', 'doseresponse_curves/drcurve_agu.pdf', 'doseresponse_curves/drcurve_alh1l2.pdf', 'doseresponse_curves/drcurve_alkb1.pdf', 'doseresponse_curves/drcurve_as2.pdf', 'doseresponse_curves/drcurve_ank1.pdf', 'doseresponse_curves/drcurve_ankrd54.pdf') sub(".*?_.*?_(.*?)\\..*", "\\1", files) [1] "aaatt" "agmk1" "agu" "alh1l2" "alkb1" "as2" "ank1" [8] "ankrd54"
Comments
Post a Comment