Replace substring with nothing


How can I replace everything starting with the _ with just nothing?

Here is a simple data frame

d <- data.frame(a = c("A_foo1", "B_foo2", " _foo3"))

I want d to look like:

a A B " "


a <- c("A_foo1", "B_foo2", " _foo3") gsub("_.*", "", a) #[1] "A" "B" " "


  • MySQL - Max() return wrong result
  • PHP request to PHP Websocket
  • In R, write each nested data frame to a CSV
  • inserting from erlang into cassandra
  • how to unescape \\\\ in a regex that has been escaped by Rails?
  • How do I remove the last vowel in a string in Ruby?
  • How can I manually set the document id in a corpus?
  • java swing resize
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • How to remove comma or any characters from Python dataframe column name
  • New dataframe with difference between first and last values of repeated measurements?
  • c++ search a vector for element first seen position
  • Is there a way to call library thread-local init/cleanup on thread creation/destruction?
  • Is there any purpose for h2-h6 headings in HTML5?
  • Javascript Array, Object, Date not defined
  • F#: In which memory area is the continuation stored: stack or heap?
  • ggplot2: make the points on the line a darker color than the line color
  • Retrieving specified columns from a list of csv files to create a data data frame in R
  • For loop with if condition on multiple R functions
  • SAXReader not re-ecape characters
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • wxPython: displaying multiple widgets in same frame
  • Unable to install Git-core+svn by MacPorts
  • Django simple Captcha “No module named fields” error
  • iOS: Detect app start via notification press
  • Could not find rake using whenever rails
  • Checking free space on FTP server
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • R - Combining Columns to String Based on Logical Match
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • embed rChart in Markdown
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal