There's nothing obviously wrong with the code you posted — I can't easily access your data (here are some methods for sharing data that are better than a screenshot), but if I invent some similar sample data the code works as I would expect it to:
set.seed(42)
tgr <- data.frame(
textForPos = rep(sample.int(10, size = 5), 2),
tablePos = rep(sample(row.names(mtcars), 5), 2),
stringsAsFactors = FALSE
)
tgr
#> textForPos tablePos
#> 1 10 Chrysler Imperial
#> 2 9 AMC Javelin
#> 3 3 Hornet Sportabout
#> 4 6 Toyota Corolla
#> 5 4 Ford Pantera L
#> 6 10 Chrysler Imperial
#> 7 9 AMC Javelin
#> 8 3 Hornet Sportabout
#> 9 6 Toyota Corolla
#> 10 4 Ford Pantera L
tgr[order(tgr$textForPos),]
#> textForPos tablePos
#> 3 3 Hornet Sportabout
#> 8 3 Hornet Sportabout
#> 5 4 Ford Pantera L
#> 10 4 Ford Pantera L
#> 4 6 Toyota Corolla
#> 9 6 Toyota Corolla
#> 2 9 AMC Javelin
#> 7 9 AMC Javelin
#> 1 10 Chrysler Imperial
#> 6 10 Chrysler Imperial
I'm glad you've got things working for you, but what you report is a bit odd. The code you posted is the standard way to reorder the rows in a data frame and keep the changes (by assigning the reordered data frame to the same name as the original data frame), so I can't imagine why tgr = tgr[order(tgr$textForPos), ] wouldn't work. Indeed, it does work if I try it:
set.seed(42)
tgr <- data.frame(
textForPos = rep(sample.int(10, size = 5), 2),
tablePos = rep(sample(row.names(mtcars), 5), 2),
stringsAsFactors = FALSE
)
tgr
#> textForPos tablePos
#> 1 10 Chrysler Imperial
#> 2 9 AMC Javelin
#> 3 3 Hornet Sportabout
#> 4 6 Toyota Corolla
#> 5 4 Ford Pantera L
#> 6 10 Chrysler Imperial
#> 7 9 AMC Javelin
#> 8 3 Hornet Sportabout
#> 9 6 Toyota Corolla
#> 10 4 Ford Pantera L
tgr <- tgr[order(tgr$textForPos),]
tgr
#> textForPos tablePos
#> 3 3 Hornet Sportabout
#> 8 3 Hornet Sportabout
#> 5 4 Ford Pantera L
#> 10 4 Ford Pantera L
#> 4 6 Toyota Corolla
#> 9 6 Toyota Corolla
#> 2 9 AMC Javelin
#> 7 9 AMC Javelin
#> 1 10 Chrysler Imperial
#> 6 10 Chrysler Imperial
(I'm personally Team <-, but choice of assignment operator shouldn't matter in this case).
I'm noticing that you're now using the textForPos variable from a different data frame — tgr2 — to order by, and assigning the re-ordered data frame to a third name. This shouldn't be necessary, unless you really do want to keep both the re-ordered and originally-ordered data frames, and either way I'm not sure what role tgr2 is playing here?