【发布时间】:2020-02-26 09:14:36
【问题描述】:
我想删除所有列中字符串中逗号和逗号后的每个字符
from <- c("UK, port unspecified", "Nantes", "London", "America", "La Martinique, port unspecified")
to <- c("Benin", "Widha", "France, *", "America, Port unspecified", "London")
network <- data.frame(from, to)
我的 df :
from to
1 UK, port unspecified Benin
2 Nantes Widha
3 London France, *
4 America America, Port unspecified
5 La Martinique, port unspecified London
我想要什么:
from to
1 UK Benin
2 Nantes Widha
3 London France
4 America America
5 La Martinique London
我可以在 dplyr 管道中组合transmute_all(或transmute_if)(dplyr 包)和split(tidyr 包)函数吗?
【问题讨论】: