本文介绍了R在列中按定界符分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多行的文件。例如
I have a file with several lines. For example
A B C
awer.ttp.net Code 554
abcd.ttp.net Code 747
asdf.ttp.net Part 554
xyz.ttp.net Part 747
我想使用R拆分表的仅列A,并且希望将新列添加到表D中,其值是awe,abcd,asdf和xyz。
I want to use R to split just column A of the table and I want a new column added to the table D, with values awe, abcd, asdf, and xyz. Would prefer this to be done using dplyr.
推荐答案
您可以使用 mutate
和 gsub
:
library(dplyr)
df = df %>% mutate(D=gsub("\\..*","",A))
A B C D
awer.ttp.net Code 554 awer
abcd.ttp.net Code 747 abcd
asdf.ttp.net Part 554 asdf
xyz.ttp.net Part 747 xyz
这篇关于R在列中按定界符分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!