Re: [R] how to exclude certain keywords in strings

2018-10-12 Thread Rui Barradas
Hello, If you want to remove everything from the last underscore to the end of the string, this regex is better. Note that you don't need gsub, 'g' is to replace all matches. x <- c("StationName1_temp.csv", "Station_Name1_temp.csv", "StationName2_temp.csv") sub("_[^_]*$", "", x) #[1] "Stati

Re: [R] how to exclude certain keywords in strings

2018-10-11 Thread Jeff Newmiller
I cannot imagine you looked very hard... this kind of question pops up all the time on this mailing list. Read the help fur the sub() function... you want to search for something and replace it with an empty string (""). You should also know by now to post plain text on this mailing list. On Oc

Re: [R] how to exclude certain keywords in strings

2018-10-11 Thread lily li
I just figured this out, which seems to be a simple question. I just used gsub("_temp.csv","","StationName1_temp.csv"). > Hi R users, > > I don't know how to extract certain words in strings. For example, if I > have strings like the formats "StationName1_temp.csv", > "StationName2_temp.csv", et

[R] how to exclude certain keywords in strings

2018-10-11 Thread lily li
Hi R users, I don't know how to extract certain words in strings. For example, if I have strings like the formats "StationName1_temp.csv", "StationName2_temp.csv", etc. How to get strings like these "StationName1", "StationName2", etc? That is to say, I want to exclude the keywords "_temp.csv", bu