![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove all text from a string before a particular character in R?
Sometimes we want to extract a sub-string from a big string and that sub-string lies after a particular character. For example, a string could be “Learning.Computer.Science.is.not.difficult-Author” and we want to extract the word Author from it. This can be done with the help of gsub function.
Examples
x1<-"Learning.Computer.Science.is.not.difficult-Author" gsub(".*-","",x1) [1] "Author" x2<-"Learning.Computer.Science.is.not.difficult Author" gsub(".* ","",x2) [1] "Author" x3<-"Learning.Computer.Science.is.not.difficult&Author" gsub(".*&","",x2) [1] "Learning.Computer.Science.is.not.difficult Author" x3<-"Learning.Computer.Science.is.not.difficult^Author" x3<-"Learning.Computer.Science.is.not.difficult&Author" gsub(".*&","",x3) [1] "Author" x4<-"Learning.Computer.Science.is.not.difficult%Author" gsub(".*%","",x4) [1] "Author" x5<-"Learning.Computer.Science.is.not.difficult#Author" gsub(".*#","",x5) [1] "Author" x6<-"Learning.Computer.Science.is.not.difficult@Author" gsub(".*@","",x6) [1] "Author" x7<-"Learning.Computer.Science.is.not.difficult~Author" gsub(".*~","",x7) [1] "Author" x8<-"Learning.Computer.Science.is.not.difficult/Author" gsub(".*/","",x8) [1] "Author" x9<-"Learning.Computer.Science.is.not.difficult;Author" gsub(".*;","",x9) [1] "Author" x10<-"Learning.Computer.Science.is.not.difficult:Author" gsub(".*:","",x10) [1] "Author" x11<-"Learning.Computer.Science.is.not.difficult< Author" gsub(".*< ","",x11) [1] "Author" x12<-"Corona Virus has changed the world -Nizam" gsub(".*-","",x12) [1] "Nizam" x13<-"Corona Virus has changed the world :Nizam" gsub(".*:","",x13) [1] "Nizam"
Advertisements