I have a variable containing university names in R:
mydata = data.frame(matrix(nrow=3))
mydata$uni <- c("University of Texas", "University of Washington", "Harvard University", "The Scripps Research Institute")
I want to end up with a variable, where the order of the words are reversed:
mydata$uni_revs <- c("Texas of University", "Washington of University", "University Havard", "Institute Research Scripps The")
I tried the approach described at the bottom of this page: https://www.codingprof.com/3-easy-ways-to-reverse-a-string-in-r/
mydata$string_split <- strsplit(mydata$uni, " ")
mydata$uni_revs2 <- paste(rev(mydata$string_split), collapse=" ")
It does not produced the desired results, as each row now simply contains "c(\"Harvard\", \"University\") c(\"University\", \"of\", \"Washington\") c(\"University\", \"of\", \"Texas\")"
which is different from the results defined in mydata$uni_revs