Created
September 23, 2024 17:33
-
-
Save DrK-Lo/3a53d5c3f3a8b7f7503d362543d03bad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have this list of IDs, and want to get the final column (right before the ".CEL" from the ID). | |
> s | |
[1] "A8_CviMVP_PlDNA_5__SG_1240__5c86242a_253268_H1.CEL" "A9_CviMVP_PlDNA_5__SG_1659__12a25bac_253268_A2.CEL" "A9_CviMVP_PlDNA_5__SG_1659__12a25bac_253268_A10.CEL" | |
This function splits the string by the "_". When doing so, the 11th value listed is the column we want and outputs eg. "H1.CEL" | |
Then we want to get rid of the ".CEL", so we substitute the ".CEL" with a "" | |
``` | |
getstring <- function(x){a<-strsplit(x,"_");sub(".CEL","",a[[1]][11],)} | |
``` | |
To apply this function to a vector, use the `lapply` function. It will return a list, so we unlist it to get a vector | |
``` | |
unlist(lapply(x,getstring)) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment