我在数据集中有一个列,其中包含类的名称(即名称重复),例如:
Class
ProjectTeam.Branch.Finder
AirPolProj.Classes.Estimate
ProjectTeam.Branch.Finder
com.ib.client.ExecutionFilter
com.ib.client.ExecutionFilter
AirPolProj.Classes.Estimate
我想替换这些值以仅在类中包括姓氏
Class
Finder
Estimate
Finder
ExecutionFilter
ExecutionFilter
Estimate
您对如何执行此操作有任何想法吗?
答案 0 :(得分:3)
df1$Class <- sub(".*[.]","", df1$Class)
答案 1 :(得分:2)
我们可以在此处使用sub
作为基本R选项:
df$Class <- sub(".*?([^.]+)$", "\\1", df$Class)
答案 2 :(得分:1)
尝试:
Class <- c(
"ProjectTeam.Branch.Finder",
"AirPolProj.Classes.Estimate",
"ProjectTeam.Branch.Finder",
"com.ib.client.ExecutionFilter",
"com.ib.client.ExecutionFilter",
"AirPolProj.Classes.Estimate")
stringr::str_extract(Class,"(?<=\\.)[^.]*$")