Try basename()
. It
removes all of the path up to and including the last path separator (if any).
basename("abcd.com/efgh/ijkl/mnop")
# [1] "mnop"
It is vectorized, so you can just stick the whole column in there.
basename(rep("abcd.com/efgh/ijkl/mnop", 3))
# [1] "mnop" "mnop" "mnop"
So, to apply this to one column link
of a data frame webdata
, you can simply do
webdata$link <- basename(webdata$link)
The other obvious function would be sub()
, but I think basename()
will do the trick and it's easier.
sub(".*/", "", rep("abcd.com/efgh/ijkl/mnop", 3))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…