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.
我有一个 data.frame 看起来像这样:
name Lily(1+2) John(good+1) Tom() Jim Alice(*+#) .....
我想删除 R 中的所有括号和括号内的所有内容。我该怎么办?
我更喜欢我的 data.frame 看起来像:
name Lily John Tom Jim Alice ....
谢谢!
# read your sample data: d <- read.table(text=readClipboard(), header=TRUE, comment='`') # remove strings in parentheses transform(d, name=gsub('\\(.*\\)', '', name)) # name # 1 Lily # 2 John # 3 Tom # 4 Jim # 5 Alice