Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎样才能以 _ 开头的所有内容都替换掉?
这是一个简单的数据框
d <- data.frame(a = c("A_foo1", "B_foo2", " _foo3"))
我希望 d 看起来像:
a A B " "
a <- c("A_foo1", "B_foo2", " _foo3") gsub("_.*", "", a) #[1] "A" "B" " "