Reputation: 2429
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
" "
Upvotes: 0
Views: 641
Reputation: 61933
a <- c("A_foo1", "B_foo2", " _foo3")
gsub("_.*", "", a)
#[1] "A" "B" " "
Upvotes: 3