问题
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
" "
回答1:
a <- c("A_foo1", "B_foo2", " _foo3")
gsub("_.*", "", a)
#[1] "A" "B" " "
来源:https://stackoverflow.com/questions/13570312/replace-substring-with-nothing