Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Delete everything after second comma from string [duplicate]

$
0
0

I would like to remove anything after the second comma in a string -including the second comma-. Here is an example:

x <- 'Day,Bobby,Jean,Gav'
gsub("(.*),.*", "\\1", x)

and it gives:

[1] "Day, Bobby, Jean"

while I want:

[1] "Day, Bobby

regardless of the number of names that may exist in x


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>