I'm trying to reverse the parts of a hierarchical name found in a dataframe so that I can work with the string for the reverse path. Here is what I did:
flip <- function(x) { # My attempted function
str <- str_split(x,":",simplify=TRUE)
paste(str[length(str):1], collapse = ":")
}
Data <- data.frame( # The data
X = c("one:two:three:four","five:six:seven:eight")
)
mutate(Data, # My attempt & result
Xflip = flip(X)
)
#> X Xflip
#>1 one:two:three:four eight:four:seven:three:six:two:five:one
#>2 five:six:seven:eight eight:four:seven:three:six:two:five:one
# What I am looking for
#> X Xflip
#>1 one:two:three:four four:three:two:one
#>2 five:six:seven:eight eight:seven:six:five
Thank you!