I have this code for trucating strings after an underscore "_" is found, but I don't understand the operators/arguments that were passed through gsub to make this manipulation possible. In particular, why I should have to gsub "\\1" instead of "". I do note that the output of gsubbing nothing removes the entire string. I am also a bit confused by how the operators are being used, particularly parantheses and brackets:
AAA <- ATGAS_1121
aa <- gsub("([^_]*).*", "\\1", AAA)
print(aa)
[1] "ATGAS"
Please note, this post draws heavily from: R remove part of string
Thanks, I appreciate it.
Aucun commentaire:
Enregistrer un commentaire