I want to replace everything after the first _ in data77298$SAMPLE.CODE
to " ", such that I get levels to be GSM2048265, GSM2048266 etc.,
Is it possible using a single command to change all strings after the underscore to null?
I want to replace everything after the first _ in data77298$SAMPLE.CODE
to " ", such that I get levels to be GSM2048265, GSM2048266 etc.,
Is it possible using a single command to change all strings after the underscore to null?
you can do it by gsub
my_string<-c("GSM2048265_Somet_323_h4554ing_here","GSM2048266_sometwewe_sdsd_hing_here")
gsub("\\_.*","",my_string)
[1] "GSM2048265" "GSM2048266"
How about:
library(stringr)
my_string<-c("GSM2048265_1_2_£_$_F_CA","GSM2048266_aasv_vaerv_vasd", "GSM2048266_arvqb_oyor_1234")
word(my_string, 1, sep = "_")