online:
http://regexr.com/
Ubuntu
kiki
This site is to serve as my note-book and to effectively communicate with my students and collaborators. Every now and then, a blog may be of interest to other researchers or teachers. Views in this blog are my own. All rights of research results and findings on this blog are reserved. See also http://youtube.com/c/hongqin @hongqin
Showing posts with label regular expressions. Show all posts
Showing posts with label regular expressions. Show all posts
Sunday, June 11, 2017
Tuesday, October 14, 2014
Monday, June 17, 2013
gsub and strplit on vector of names
#I want to remove '_alpha' in this list
myInput = c( "afg3_alpha", "alg12_alpha", "dbp3_alpha", "elp4_alpha", "fob1_alpha", "gpr1_alpha")
#my current solution
tmpsplit = strsplit(myInput, '_')
tmp = NA
for (item in tmpsplit){
tmp = c(tmp, item[1])
}
results1 = tmp[-1];
#this is what I need, but I want a better solution.
#Here is what I come up with, but it is pretty awkward
tmp3 = lapply(myInput, FUN=function(x){strsplit(x, '_')[[1]][1]})
results2 = unlist(tmp3)
#gsub is the best solution
gsub("_.*", "", myInput)
myInput = c( "afg3_alpha", "alg12_alpha", "dbp3_alpha", "elp4_alpha", "fob1_alpha", "gpr1_alpha")
#my current solution
tmpsplit = strsplit(myInput, '_')
tmp = NA
for (item in tmpsplit){
tmp = c(tmp, item[1])
}
results1 = tmp[-1];
#this is what I need, but I want a better solution.
#Here is what I come up with, but it is pretty awkward
tmp3 = lapply(myInput, FUN=function(x){strsplit(x, '_')[[1]][1]})
results2 = unlist(tmp3)
#gsub is the best solution
gsub("_.*", "", myInput)
Subscribe to:
Posts (Atom)


